I retrieved array data with checkbox using React. But if I checked one checkbox, it checks all. I want to show one text box if I checked one checkbox. How can I solve it?
class ColumnName extends Component {
constructor(props) {
super(props);
this.state = { checked: false };
}
render() {
if (!this.props.posts) {
return <div />;
}
const content = this.state.checked ? <div> Content </div> : null;
return (
<ul>
{this.props.posts.map(post => (
<div>
<Checkbox
checked={this.state.checked}
onChange={() => {
this.setState({
checked: !this.state.checked
});
}}
>
{post.title}
</Checkbox>
{content}
</div>
))}
</ul>
);
}
}
export default Search;