Skip to content

@formily/reactive 是否支持多实例? #3860

Closed Answered by bigmeow
bigmeow asked this question in Q&A [2.x]
Discussion options

You must be logged in to vote

我想到种写法,配合context和Provider:

import { createContainer } from "unstated-next"

export const container = createContainer(() => {
  const store = model({
    count: 0,
    count2: 1,
    increment() {
        store.count ++
    },
    increment2() {
        store.count2 ++
    },
  })
  return store 
})

const Index = observer(() => {
    const store = container.useContainer()
    return <View>{store.count}</View>
})

const App = () => {
  return <container.Provider><Index/></container.Provider>
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bigmeow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant