useLocalModel

information

By default, the export package name for all APIs in this section is: @modern-js/runtime/model.

If Reduck is integrated separately from Modern.js, the export package name is: @modern-js-reduck/react.

To use the State in the Model as a local state, the effect is similar to React's useState. useLocalModel API same as useModel. For detail, see useModel.

Example

function Container() {
  const [state, actions] = useLocalModel(modelA);
  const [state1, actions1] = useLocalModel(modelA);

  // ...
}

modelA was loaded twice with useLocalModel above, because useLocalModel consumes local state, so state and state1 are also completely isolated.

More
ON THIS PAGE