I am new to React. I have an array variable but when I call map function it doesn't work. I get "Uncaught (in promise) TypeError: this.state.products.map is not a function"
class Child extends React.Component {
constructor(props) {
super(props);
this.state = {
products: []
};
componentDidMount() {
fetch(url)
.then((Response) => {
this.setState({
products: Response.json()
});
})
.catch(err => console.error);
}
}
render() {
return (
<div>
<div className="col-lg-12">
{this.state.products.map(product1 => (
<Button key={product1.id} style={{ color: 'grey', radius: '5px', width: '90px' }}>
{product1.title}
</Button>
))}
<br /><br /><br />
</div>
</div>
);
}
}
export default Category;
Where am I going wrong? Thank you.
console.log(Response.json())