Replies: 2 comments 2 replies
-
Eg. const TimerView = observer(({ id }) => {
// Grab the timer from the context.
const timer = useContext(TimersContext).get(id)
return (
<span>Seconds passed: {timer.secondsPassed}</span>
)
})
ReactDOM.render(
<TimersContext.Provider value={new Timers()}>
<TimerView id="timer1" />
<TimerView id="timer2" />
<TimerView id="timer3" />
</TimersContext.Provider>,
document.body
) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Another example with const TimerView = observer(() => {
const [timer] = useState(() => new TimerStore())
return (
<span>Seconds passed: {timer.secondsPassed}</span>
)
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! An example from the documentation:
I want each
<Timer View />
component to have its ownTimer
mobx store(or own state) and its state to be independent of the other<Timer View />
andTimer
.You have to understand that
<Timer View />
andTimer
can be a big component with a lot of logic.It would be great if the number of
<Timer View />
could be dynamic or at least generated once.Any ideas? Is it possible?
Beta Was this translation helpful? Give feedback.
All reactions