0

React's documentation has handle change function which retrieves object key at the run time.

https://reactjs.org/docs/forms.html#handling-multiple-inputs

I have similar;

//handles state change
handleChange = prop => event => {
    this.setState({[prop]: event.target.value})
}

As far as I understand uglify plugin is changing key names at build time so how can/should I handle this?

Example: Let's say we have handleChange('name'), but in build time state.name becomes lets say state.n but It's updating state.name not state.n

Thank you.

Mohamed
  • 1,129
  • 1
  • 13
  • 32
  • what do you mean? have you tried it and it didn't work? if it will change a key name in one place it will change it on all other places that this variable name exists – Sagiv b.g Mar 05 '18 at 21:58
  • With computed property names, it's not the name of the variable that matters (i.e. `prop`), but its value (what value does `prop` hold?). Your example should work fine as-is. – Alex Mar 05 '18 at 21:59
  • It looks like not working as expected. I've added example case. – Mohamed Mar 05 '18 at 22:13
  • IIRC uglify won't touch strings, so if you're passing string literals to `handleChange` (as you have in your example) then it's not actually a dynamic value, and won't be minified. I vaguely recall this was how Angular 1 got around avoiding minification of meaningfully named variables. – monners Mar 05 '18 at 22:43

0 Answers0