Dhananjay Sharma
Dhananjay Sharma

Reputation: 134

Bind select react-hook-form

https://codesandbox.io/s/dhananjay-rtb8r?file=/src/App.js

Please look sample code. I want to bind city based on state

Upvotes: 1

Views: 355

Answers (1)

CevaComic
CevaComic

Reputation: 2114

You can use Array.filter() , and then Array.map() to create your sub menu.

Documentation here

Example :

city.filter(city => city.scopeId === state.id).map(city => <MenuItem {...city} />)

EDIT:

Hook example:

React.useEffect(() => {
    const getData = async () => {
        const result = await axios.get('api-url/?state=' + state)
        // for post requests with params , i suggest you use qs library
        // const result = await axios.post('api-url/',qs.stringify({state}))
        return result
    }
    const city = getData()
    setState(oldState => ({...oldState,city}))
},[state])

Upvotes: 1

Related Questions