Search code examples
reactjsreact-hooksuse-effectuse-state

How could i send the setStateAction in useState React


const [SBMenu,setSBMenu] = useState(<MainMenu Menu={setSBMenu}/>)

how could i send the setStateAction in useState . I Know that we can't but is there any solution to send it because we can't access to the setStateAction before initialization


Solution

  • Don't know why you want to set a rendered component as a state, it's not very common.

    Suppose you want to do that, you can't have a cyclic logic

      const [a, b] = fn(c(b))
    

    b is not defined yet. You most likely need to think of what's b first in your code.