Member-only story

ReactJS Interview and Prep: Top 11 Questions and Answers

Marika Lam
5 min readJun 19, 2024

--

  1. What happens with a component when it receives new props?
  • The component will update. A component updates when it receives new props or state, usually in response to an interaction.

2. Describe how to use useState

  • useState is a React hook that lets you add a state variable to your component in functional components. You pass the initial state to this function, and it returns a variable with the current state value (not necessarily the initial state) and another function to update this value.
  • useState is equivalent of this state / this.setState for functional components
const [state, setState] = useState(initialState)

3. How can you share a state between multiple components?

  • Parent to child: Props or instance methods
  • Child to parent: Callback functions or event bubbling. Callback function is a function which is to be executed after another function has finished execution.
  • Sibling to sibling: Parent component (lifting state up)
  • Any to any: Observer Pattern, Global variables or Context

4. Do you have to use React with JSX?

No. JSX is not a requirement for using React. Using React without JSX is convenient when you don’t want to set up compilation in your build environment.

--

--

No responses yet