I have two buttons (icons). Depending on which one I click (parameter), a function should be called to change my view layout.
export default class ToolbarPictograms extends Component {
static propTypes = {
layout: PropTypes.string.isRequired,
changeLayout: PropTypes.func.isRequired
}
constructor(props) {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick = value => {
this.props.changeLayout(value)
}
render() {
const changeLayout = this.props.changeLayout
return (
<div style={style.container}>
<Divider />
<div className='row end-xs'>
<ViewListIcon onClick={() => changeLayout('list')} />
<ViewModuleIcon onClick={() => changeLayout('modules')}/>
</div>
<Divider />
</div>
)
}
}
Currently I use arrow functions, it works but I have a warning: JSX props should not use arrow functions
What is the best way to do something like this in React?