React.js QuickTips

PURPOSE

Storing Tips here for future reference

Returning Multiple Rows in same Function without warning or error

When we have to render multiple trs inside of a function and we try something like

React will throw error about JSX expressions having one parent element

If we wrap it inside a div

We get a warning about how divs cannot be children of table elements

The correct way to do this would be using Fragments, which was introduced in React 16

Note that there might be a warning about each element having a unique key prop Just add the key attribute in all your components don't currently have one, including the Fragment.


React not identifying function as React Component

If you see an error such as:

All you need to do this, capitalize the first letter of your component due to react conventions.

So this:

becomes this:


Adding multiple classNames to an element

The simplest approach is to use concatenation:

Thank the author. Fork this blog.


Tagged in javascriptreactreactjs