hi i am new to react redux i am working on a project and in that project i have a checkbox menu when user select anything from that menu then the state is update noew i want to pass that state into another component how can i do that
here is my code for checkbox menu (this is my dropdown class)
<MultiSelect
options={this.state.zone_account}
selected={this.state.selected}
onSelectedChanged={this.selected}
/>
selected = (selected) => {
// selectedFruits is array of { label, value }
this.setState({ selected },()=>{
console.log("selected list checkbox",this.state.selected)
// sessionStorage.setItem(recent_slected_user_accountsid+"selected zones",this.state.selected)
sessionStorage.setItem(recent_slected_user_accountsid+"selected zones_ID",this.state.selected)
})
}
here is selected state that i want to pass into another component and the code of another component is
this i smy anohter compoent
```
class Overview extends Component {
constructor(props) {
super(props);
}
render(){
return(
<div>
//here i want to use that slelected state
</div>)
}
1 Answer
You can do simply by doing this:
Parent.js (Parent component)
import Overview from './Overview'; //Import your overview component
<MultiSelect
options={this.state.zone_account}
selected={this.state.selected}
onSelectedChanged={this.selected}
/>
selected = (selected) => {
// selectedFruits is array of { label, value }
this.setState({ selected },()=>{
console.log("selected list checkbox",this.state.selected)
// sessionStorage.setItem(recent_slected_user_accountsid+"selected zones",this.state.selected)
sessionStorage.setItem(recent_slected_user_accountsid+"selected zones_ID",this.state.selected)
})
}
<Overview selectedValue={this.state.selected}/> //<-Note this
Basically where you are selecting state in that same component you need to import Overview
component.And then you can easily pass state from there to another components
Your Answer
asked | |
viewed | 44 |
Related
- 1Generating a series of colors between two colors
- 1What is the difference between setTimeout and setInterval?
- 3What's the difference between using “let” and “var”?
- 1How to update parent state from child component in React?
- 1how to write function to generate an array between two integers
- 0What is the difference between custom dimensions and metrics in Google Analytics
- 1How to Pass vector as a function parameter in C++
- 2How can I pass variables and data from PHP to JavaScript?
- 2How to set distance between flex-box items?
- 1setState doesn't update the state immediately
- 1What is difference between TCP and UDP