How can I create the method when I click on one checkbox other checkbox unselceted and just can select one of them.
import React, { Component } from 'react';
export default class Tablerow extends Component {
constructor(props){
super(props);
let {listwebsites} = this.props;
listwebsites.checked = false;
this.state = {
fields : {
id: listwebsites.id
}
}
this.click = this.click.bind(this);
this.selectOnlyThis = this.selectOnlyThis.bind(this);
}
click(value){
this.props.handleChangess(this.state, value);
};
render() {
const {listwebsites} = this.props;
return (
<tr>
<td><input id={`checkbox_${listwebsites.id}`} value={listwebsites.checked} onChange={e => this.click(e.target.checked)} type="checkbox" name="record"/></td>
<td>{listwebsites.name}</td>
<td>{listwebsites.url}</td>
</tr>
)
}
}
Tablerowcomponent should be stateless (i.e. controlled) and the parent component should hold an array of selected rows as its state.