ReactJs This.state is 0 inside .map reactjs this is undefined,reactjs this keyword,reactjs this.setstate,

Iam trying to convert all selected item id's from a redux store into the item names and save it into state.

My problem is that the spread operator inside the setState function is equal to zero. Do I have to bind the context of the function to the class?

  constructor(props) {
    super(props);
    this.state = {
      item_Name: []
    };
}




  componentDidMount() {
    this.props.Cart_Items.Id.map((item, i) => {
      if (item === "001") {
        // The problem is that this.state.item_Name is 0
        console.log(this.state.item_Name)
        this.setState({
          item_Name: [...this.state.item_Name, "Buddha"]
        });
      }
    })
  }

Thanks for your help!

Answer:1



  1. reactjs this is undefined
  2. reactjs this keyword
  3. reactjs this.setstate
  4. reactjs this.setstate is not a function
  5. reactjs this.props
  6. reactjs this.state
  7. props.children in react js
  8. reactjs this.props.history undefined

In a small React/Redux app that I am writing, I have a thunk that looks as follow: updateCategory(category){ return function(dispatch, getState){ dispatch({ type : types....

In a small React/Redux app that I am writing, I have a thunk that looks as follow: updateCategory(category){ return function(dispatch, getState){ dispatch({ type : types....

I'm trying to implement redux-orm and not sure of the best way to handle updating meta properties on my models. The return value of static reducers are ignored in the latest version, and looking ...

I'm trying to implement redux-orm and not sure of the best way to handle updating meta properties on my models. The return value of static reducers are ignored in the latest version, and looking ...