React is the most popular frontend library of framework right now and if it keeps evolving often.
It has some many tricks under the hood that even experienced professionals fails at interviews.
In this set we have curated list of react js interview questions and answers which are differentiated topic wise. Each question will have its topic’s tag and difficulty label.
1. Which among the following is the correct way of rendering HTML in react?
//1 render() { return false } //2 render() { return null } //3 render() { return [] } //4 render() { return <React.Fragment></React.Fragment> } //5 render() { return <></> }
ReactRenderingComponenteasy
Options
Answer
1, 2, 3, 4
In react we can return falsy values to render nothing
Is this a correct way to print JSON as it is in react?
import React, {Component} from 'react'; const data = { name: 'Prashant', age: 24 } class App extends Component { render() { return ( <pre> {JSON.stringify(data, null, 2)} </pre> ) } } export default App;
ReactRenderingeasy
Options
Answer
1, 3
JSON.stringify()
converts a json to a string which can then be shown in pre tag.