locked
a quick binding issue RRS feed

  • Question

  • User1034446946 posted

    Hi

    if i have a direct reference like state[someProperty].someProperty[someOtherProperty].someOtherProperty[anotherProperty].flag

    how do i use it instead of doing

    {...prevState,someProperty: 
        {...prevState.someProperty,someOtherProperty:  
    {...prevState.someProperty.someOtherProperty,anotherProperty:
    {...prevState.someProperty.someOtherProperty.anotherProperty, flag: false
    } } } }

    the only way i can think is just return an array of keys an split itinstead of the binding

    (this is for modifiying state)

    Saturday, September 14, 2019 3:08 PM

Answers

  • User-474980206 posted
    You should look at flattening your state. You also might be interested in immutability helpers.

    https://reactjs.org/docs/update.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 15, 2019 5:02 PM

All replies

  • User-474980206 posted
    You should look at flattening your state. You also might be interested in immutability helpers.

    https://reactjs.org/docs/update.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 15, 2019 5:02 PM
  • User1034446946 posted

    i haven't found an immutable helper i like, I have flatterned my state as much as i can get it, the most it goes is 3 tiers i think

    Monday, September 16, 2019 10:00 PM