ShakaCode | ShakaCode Blog | Rails On Maui Blog | Rails | ReactJs | JavaScript | Webpack | Productivity |

React on Rails addons


#1

How can i use react-addons?
I used to do it in gem react-rails like this

var index, records;
index = this.state.records.indexOf(record);
records = React.addons.update(this.state.records, {
  $splice: [[index, 1, data]]
});
return this.replaceState({
  records: records
});

how would i use React.addons.update in react_o_rails?


#2

What doesn’t work in React on Rails. This looks like standard JavaScript.


#3

I got it working using the immutability-helper package.

  1. Go to the client folder in the terminal.
  2. Type ‘npm install immutability-helper --save’ into the console.
  3. import update from ‘immutability-helper’;
  4. var posts = update(this.state.posts, { $push: [post] });
    this.setState({
    posts: posts
    });

The addons.update method is deprecated.