-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scoped state tracking #479
Comments
@christianalfoni from example page: // components/Todos.tsx
import * as React from 'react'
import { useAppState } from '../overmind'
import Todo from './Todo'
const Todos = ({ id }: { id: string }) => {
const state = useAppState()
return (
<ul>
{Object.keys(state.todos).map(id => <Todo key={id} id={id} />)}
</ul<
)
}
export default Todos
// components/Todo.tsx
import * as React from 'react'
import { useAppState } from '../overmind'
const Todo = React.memo(({ id }: { id: string }) => {
const todo = useAppState(state => state.todos[id])
return <li>{todo.title}</li>
})
export default Todo Does it actually work? Overmind version:
UPDATE:Issue is actual for Next.js, while code works on server-side. On a client-side there is no issue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: