What is mapDispatchToProps?

I feel like none of the answers have crystallized why mapDispatchToProps is useful. This can really only be answered in the context of the container-component pattern, which I found best understood by first reading:Container Components then Usage with React. In a nutshell, your components are supposed to be concerned only with displaying stuff. The only place they are supposed to get information from is … Read more

How do I reference a local image in React?

First of all wrap the src in {} Then if using Webpack; Instead of: <img src={“./logo.jpeg”} /> You may need to use require: <img src={require(‘./logo.jpeg’)} /> Another option would be to first import the image as such: import logo from ‘./logo.jpeg’; // with import or … const logo = require(‘./logo.jpeg); // with require then plug it in… … Read more

When to use componentWillReceiveProps lifecycle method?

componentWillReceiveProps is required if you want to update the state values with new props values, this method will get called whenever any change happens to props values. In your case why you need this componentWillReceiveProps method? Because you are storing the props values in state variable, and using it like this: this.state.KeyName That’s why you … Read more

Difference between npx and npm?

NPM – Manages packages but doesn’t make life easy executing any.NPX – A tool for executing Node packages. NPX comes bundled with NPM version 5.2+ NPM by itself does not simply run any package. it doesn’t run any package in a matter of fact. If you want to run a package using NPM, you must specify that package in your package.json file. When executables are installed via NPM packages, NPM links to … Read more

How to do a redirect to another route with react-router?

For the simple answer, you can use Link component from react-router, instead of button. There is ways to change the route in JS, but seems you don’t need that here. To do it programmatically in 1.0.x, you do like this, inside your clickHandler function: this.history.pushState(null, ‘login’); Taken from upgrade doc here You should have this.history … Read more

Understanding unique keys for array children in React.js

You should add a key to each child as well as each element inside children. This way React can handle the minimal DOM change. In your code, each <TableRowItem key={item.id} data={item} columns={columnNames}/> is trying to render some children inside them without a key. Check this example. Try removing the key={i} from the <b></b> element inside … Read more

React.js: Set innerHTML vs dangerouslySetInnerHTML

Yes there is a difference! The immediate effect of using innerHTML versus dangerouslySetInnerHTML is identical — the DOM node will update with the injected HTML. However, behind the scenes when you use dangerouslySetInnerHTML it lets React know that the HTML inside of that component is not something it cares about. Because React uses a virtual … Read more