If-Else in JSX
  • References/JavaScript/React/Tips

if-else statements don't work inside JSX. This is because JSX is just syntactic sugar for function calls and object construction. Take this basic example:

2025-01-10 15:47:30
Communicate Between Components
  • References/JavaScript/React/Tips

For parent-child communication, simply pass props. For child-parent

2025-01-10 15:47:30
Expose Component Functions
  • References/JavaScript/React/Tips

There's another (uncommon) way of communicating between components: simply expose a method

2025-01-10 15:47:30
Value of null for Controlled Input
  • References/JavaScript/React/Tips

Specifying the value prop on a controlled component prevents the user from changing the input unless

2025-01-10 15:47:30
Dangerously Set innerHTML
  • References/JavaScript/React/Tips

Improper use of the innerHTML can open you up to a cross-site scripting

2025-01-10 15:47:30
Inline Styles
  • References/JavaScript/React/Tips

In React, inline styles are not specified as a string. Instead they are specified with an object whose key is the camelCased version of the style name, and whose value is the

2025-01-10 15:47:30
Props in getInitialState Is an Anti-Pattern
  • References/JavaScript/React/Tips

This isn't really a React-specific tip, as such anti-patterns often occur in code in general; in this case, React simply points them out more clearly.

2025-01-10 15:47:30
False in JSX
  • References/JavaScript/React/Tips

Here's how false renders in different situations: Renders as id="false":

2025-01-10 15:47:30
this.props.children undefined
  • References/JavaScript/React/Tips

You can't access the children of your component through this.props.children. this.props.children designates the children being passed onto

2025-01-10 15:47:30
Maximum Number of JSX Root Nodes
  • References/JavaScript/React/Tips

Currently, in a component's render, you can only return one node; if you have, say, a list of divs to return, you must wrap your components within

2025-01-10 15:47:30