I am creating a Project where I need to get value of a component state value to another component.
How can I get the value?
Information
- Both are functional component.
- I need to send data from A (state) to B(state).
- A state data are set from
react dropdown
menu.Which is a button. - I don’t use
Link or Route
toA
dropdown that’s why I can’t get it withuseParams()
- I need to set value in
B
component which will fetch data with passing language. - I have import all needed things & don’t have any warnings & error.
Code of component A
- Send value from this
language
state toB
const A = () => {
const [language, setLanguage] = useState('en');
return (
<Navbar expand="xl" bg='light' expand={false}>
<Container>
<DropdownButton id="dropdown-basic-button" title={<MdOutlineLanguage />}>
<Dropdown.Item as="button" onClick={() => setLanguage('en')}>English</Dropdown.Item>
<Dropdown.Item as="button" onClick={() => setLanguage('ar')}>العربية</Dropdown.Item>
<Dropdown.Item as="button" onClick={() => setLanguage('bn')}>বাংলা</Dropdown.Item>
</DropdownButton>
</Container>
</Navbar>
)
};
export default A
Code of Component B
- I need to get here
A
state value & set it toB
state. Then pass touseGetDataQuery
& fetch data.
const B = () => {
let [language, setLanguage] = useState('en')
const { data } = useGetDataQuery({language })
return (
<>
</>
)
}
export default B