Skip to content

Recursive react render bug #420

@HexaField

Description

@HexaField

The following code will cause a recursive render loop. Changing state2 from {} to a primitive value (such as true) OR removing the .value stops the behavior. Is this intentional? Why is using .value in dependencies like this causing a recursive re-render? In virtually all other cases, using .value in a dependency does not cause re-renders of any kind.

const Child = (props: { state: any }) => {
  const state2 = useHookstate({})
  
  useEffect(() => {
    props.state.set({})
  }, [state2.value]) // getting rid of .value here solves the problem
  
  return <></>
}

const Parent = () => {
  const state = useHookstate({})

  useEffect(() => {
    console.log('state', state.value)
  }, [state])

  return <Child state={state} />
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions