I am trying to accomplish a relevant simple task in React while using MUI which is:
- Make a component for RadioGroup
- Implement the component inside other one
- Pass the value and the handler (onChange)
Usually everything works fine before when I made my own radio buttons but when I am using MUI radio buttons, state dose not pass as a value and the handler dose not fire. Please take a look on the code snippet. Thank you in advance
import React, { Component} from 'react';
import { FormControl, FormControlLabel, RadioGroup, Radio } from '@material-ui/core';
class example extends Component{
render(){
return(
<FormControl component="fieldset">
<RadioGroup
value={this.props.value}
onChange={this.props.handler}
row aria-label="something"
aria-label="something"
name="radio-something-group"
>
<FormControlLabel value="example1" control={<Radio />}
label="Example 1" />
<FormControlLabel value="example2" control={<Radio />}
label="Example 2" />
</RadioGroup>
</FormControl>
);
}
}
export default example;
import React, { Component} from 'react';
import example;
class implment extends Component{
state = {value = "example1"}
handler(e)
{
this.setState({ value: e.target.value});
}
render(){
return(
<example value={value} onChange={this.handler} />
);
}
}
export implment;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>