You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By extending the signature of useAppState we can scope the tracking of state.
constItem=({ id })=>{constitem=useAppState(state=>state.items[id])// Tracks ["items.$id"] and any other accessed state on item}
This is different than doing:
constItem=({ id })=>{constitem=useAppState().items[id]// Tracks ["items", "items.$id"] and any other accessed state on item}
The second example here also tracks the "items" themselves, meaning any added/removed items will cause this component to reconcile. We can currently solve this by passing the whole item down to the component, and do useAppState without using any actual state... this new solution seems more intuitive.
The text was updated successfully, but these errors were encountered:
// components/Todos.tsximport*asReactfrom'react'import{useAppState}from'../overmind'importTodofrom'./Todo'constTodos=({ id }: {id: string})=>{conststate=useAppState()return(<ul>{Object.keys(state.todos).map(id=><Todokey={id}id={id}/>)}</ul<)}exportdefaultTodos// components/Todo.tsximport*asReactfrom 'react'
import{useAppState}from '../overmind'
constTodo=React.memo(({ id }: {id: string})=>{consttodo=useAppState(state=>state.todos[id])return<li>{todo.title}</li>})exportdefaultTodo
Does it actually work? const todo = useAppState(state => state.todos[id]) returns the whole state object (root state), not specific todo, but Typescript says it's specific todo, not root state.
By extending the signature of
useAppState
we can scope the tracking of state.This is different than doing:
The second example here also tracks the "items" themselves, meaning any added/removed items will cause this component to reconcile. We can currently solve this by passing the whole item down to the component, and do
useAppState
without using any actual state... this new solution seems more intuitive.The text was updated successfully, but these errors were encountered: