Category : setstate

I’m new to React and been struggling with my code and can’t find what I’m doing wrong, This is my code export class MainPage extends Component { constructor(props){ super(props); this.state = { pn_list : [] } } componentWillMount() { axios.get(‘http://localhost:8080/pn_info/over_30’) .then((response) => { this.setState( {pn_list : response.data} ) }) } render() { return( <div> <SelectionMenu ..

Read more

I’ve got a code const importPost = (e, savedAttributes) => { await Promise.all( e.map( async (element, key) => { let product_id let productData = { name: element[‘Nazwa’], short_description: element[‘Krótki opis’], description: element[‘Opis’], backorders: element[‘Pozwalać na zamówienie oczekujące?’] == 0 ? ‘yes’ : ‘no’, sku: element[‘Sku’], slug: element[‘Slug’], type: e.length == 1 ? ‘simple’ : ‘variable’, ..

Read more

I am trying to create some Navbar dropdown buttons, I have dynamically added the buttons and I am trying to add the onclick event which just toggles the selected button/item/Object in Section array from state through setState. I have tried almost everything I could look up from internet and the errors keep popping. If anyone ..

Read more

I have the following code: Parent component: class App extends Component { state = { colors: [] }; async componentDidMount() { const fetched = await fetch("./response.json"); const fetchedJson = await fetched.json(); const res = fetchedJson.colors; this.setState({ colors: res }); } filterItems = (name) => { const lowerCaseName = name.toLowerCase(); const newColors = […this.state.colors]; const res ..

Read more