I am trying to pass attributes from SELECT button (children component) to the Parent component. I am trying to console log the attributes but when I load the app and console log (this.props) I just receive {} and the object without attribute values just with methods. Can anyone help me as I am new with React. I am doing anything wrong? Can I pass props like that?Thanks in advance Parent component:
import React, { Component } from 'react';
import Button from '@material-ui/core/Button';
import FilterMenu from "./selectButton";
import FetchRandomBet from "./fetchRandomBets";
class Betslip extends Component {
render() {
console.log("props", this.props);
return (
<div className="betslip">
<div className="betslip-top">
<h1 className="text">BETSLIP</h1>
<p className="text-two">BET WITH US!</p>
<div>
<FilterMenu />
</div>
</div>
<div>
<FetchRandomBet />
</div>
<Button className="betnow" variant="contained">
Bet Now!
</Button>
</div>
);
}
}
export default Betslip;
children component:
import React, { useState } from 'react';
import Select from 'react-select'
function FilterMenu() {
const data = [
{
value: 0,
label: "No Filter"
},
{
value: 1,
label: "Less than two"
},
{
value: 2,
label: "More than two"
},
]
const [selectedValue, setSelectedValue] = useState(null);
const handleChange = obj => {
setSelectedValue(obj);
}
return (
<>
<Select
options={data}
value={selectedValue}
onChange={handleChange}
/>
{/* <h1>{JSON.stringify(selectedValue, null, 1)}</h1> */}
</>
)
}
export default FilterMenu;