Troubleshooting
A nested update throws that a path was not found
Section titled “A nested update throws that a path was not found”The parent object or array does not exist. The library does not create missing parents automatically.
Add the full structure to <Root initial={...}> before writing the nested path:
<Root initial={{ todos: [{ done: false }] }}> <App /></Root>Then a path such as 'state.todos[0].done' can be updated.
My component did not re-render after a nested update
Section titled “My component did not re-render after a nested update”Check what the component selects. Nested writes mutate the existing parent object, so a component selecting 'state.user' can keep the same snapshot reference when 'state.user.name' changes. Select 'state.user.name' directly, or replace state.user with a fresh object.
Function selectors run after every update, but React still compares the returned snapshot. Returning the same object reference—or always creating a new object—can produce behavior different from selecting a changed primitive leaf.
My initialValue replaced existing state
Section titled “My initialValue replaced existing state”The optional second argument to useNativeState is scheduled as a write after render; it is not checked against the current value first. Initialize shared state in <Root initial={...}> and leave the hook’s second argument out when state may already exist.
setValue(previous => ...) stored a function
Section titled “setValue(previous => ...) stored a function”The setter takes a value, not a React state updater. Calculate the next value from the current hook snapshot:
const [count, setCount] = useNativeState('state.count');setCount(count + 1);A path returns undefined
Section titled “A path returns undefined”Verify the path spelling, initial state shape, and capitalization. Use state. or state. as the root prefix and numeric brackets for arrays, for example 'state.todos[0].title'.
Two roots appear to share state
Section titled “Two roots appear to share state”That is expected: <Root> initializes one module-level store; it does not create an isolated store for each React root. This package does not support independent stores.