Node / React cheat sheet

Create a react application

c:\ npx create-react-app my-app

If the creation of react app is generating error like ‘Unexpected end of JSON input while parsing near …’

c:\ npm cache clean –force

Correct way of updating the state variable

this.setState((state, props) => ({ counter: state.counter + props.increment }));

this.setState(function(state, props) { return { counter: state.counter + props.increment }; });

When we would need to return multiple <td> elements in order for the rendered HTML to be valid. If a parent div was used inside the render() , then the resulting HTML will be invalid.


To avoid this, use Fragment

function ListItem({ item }) {
  return (

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.