ReactJS Interview Questions

Ever wondered what interview questions you’ll be asked for a Front End Develop ReactJS position.

Here are some common questions and answers to ReactJS interview questions.

What is JSX?

It stands for JavaScript and XML. It’s syntactically responsible for React createElement. React uses JSX to compile down into Elements.

Why is class className in React?

It’s because class is a reserved keyword in JavaScript, so when the JSX compiles down into Elements, it results in an error, so we use className in JSX.

Describe how data flow works in React.

All components in react have a parent child component relationship. Then data flows down. from above, flowing unidirectional. We pass information in the most basic way with props and state. Global state management can share data multiple layers deep. Context, global state and redux can prevent passing data unidirectional down from parent to child.

How would you delay an API call until a component is mounted?

Use componentDidMount, a component Lifecycle method. Another way is to use useEffect hook and pass an empty array as second argument, it mimics componentDidMount. When you pass certain variables to the useEffect second argument, useEffect will run when these variables change. Functional components with hooks are the most modern ReactJS development procedure.

Should you use Ternaries or && operator to conditionally render React components?

Sometimes if you check the length of a variable a 0 gets rendered to the page. Basically JavaScript knows that 0 zero and something is always going to be “falsey” so it doesn’t bother evaluating the right side of the expression. Ternaries are better to help avoid printing 0 zero to the screen.

More details regarding using Ternaries rather than && operators in JSX: https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx