[Code Example] Create immutable copy of object in reactjs

Total
0
Shares

To create immutable copy of object in reactjs, you can use Object.assign() method. This method is also used to create a copy of state object. Since states should not be updated directly so in order to work with state data, it is recommended to create a distinct copy of it.

var player = {score: 1, name: 'Jeff'};

var newPlayer = Object.assign({}, player, {score: 2});

Source: ReactJs Docs

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like