Looking to pass all props using react hooks

13,324

Yes, you can use context API. It was implemented for the same purpose (when passing props down the children's components).

Also, you can do something like below for the class components:

<SomeComponent {...this.props} />

and for functional components:

<SomeComponent {...props} />
Share:
13,324
steelyphil
Author by

steelyphil

Let's connect on Linkinedin https://www.linkedin.com/in/nguyephi/

Updated on June 12, 2022

Comments

  • steelyphil
    steelyphil almost 2 years

    Is there a simple way to pass all props of a parent component to a child component when using hooks?

    It seems to get repetitive sending each state to each component.

    I'm wondering if spread operator works and if so what the proper syntax is?

    I apologize for not providing an example, had to leave. The example is something to what I'm doing.

    const Parent = () => {
        const [count, setcount] = useState(0)
        const [example, setExample] = useState('')
    
        return (
            <Child props={...How to pass all props in the state} 
        )
    }