React Questions
React Questions
3. How can you access the state of a component from inside of a member function?
a) this.getState() c) this.state
b) this.prototype.stateValue d) this.values
6. Which of the following is the correct data flow sequence of flux concept?
a) Dispatcher->Action->Store->View c) Action->Dispatcher->View->Store
b) Action->Dispatcher->Store->View d) Action->Store->Dispatcher->View
7. At the highest level, React components have lifecycle events that fall into
a) Initialization c) Destruction
b) State/Property Updates d) All of these
8. If a function component should always render the same way given the same props, what is a simple
performance optimization available for it?
a) Wrap it in the React.memo higher-order component.
b) Implement the useReducer Hook.
c) Implement the shouldComponentUpdate lifecycle method.
d) Implement the useMemo Hook.
9. How do you fix the syntax error that results from running this code?
1
React JS
10. Using object literal enhancement, you can put values back into an object. When you log person to the
console, what is the output?
render(){
let langs = ["Ruby","ES6","Scala"]
return (<div>
{langs.map(it => <p>{it}</p>)}
</div>)
}
a) Error. Cannot use direct JavaScript code in JSX
b) Error. Should be replaced with a for..loop for correct output
c) Displays the list of languages in the array
d) Displays nothing
12. How do you write an inline style specifying the font-size:12px and color:red; in JSX
a) style={{font-size:12,color:'red'}} c) style={fontSize:'12px',color:'red'}
b) style={{fontSize:'12px',color:'red'}} d) style={{font-size:12px,color:'red'}}
13. Which method in a React Component should you override to stop the component from updating?
a) willComponentUpdate c) componentDidUpdate
b) shouldComponentUpdate d) componentDidMount
16. To get the first item from the array ("cooking") using array destructuring, how do you adjust this line?
17. What should the console read when the following code is run?
2
React JS
c) Mouse d) None of the above
18. What is the name of the tool used to take JSX and turn it into createElement calls?
a) JSX Editor c) Browser Buddy
b) ReactDOM d) Babel
19. Which props from the props object is available to the component with the following syntax?
20. What does this React element look like given the following function?
21. Consider the following code from React Router. What do you call :id in the path prop?
22. What do you call the message wrapped in curly braces below?
23. You have written the following code but nothing is rendering. How do you fix this problem?
24. Why is it important to avoid copying the values of props into a component's state where possible?
a) because you should never mutate state
b) because you want to allow data to flow back up to the parent
c) because getDerivedStateFromProps() is an unsafe method to use
d) because you want to allow a component to update in response to changes in the props
3
React JS
25. How do you destructure the properties that are sent to the Dish component?
function Dish(props) {
return (
<h1>
{props.name} {props.cookingTime}
</h1>
);
}
a) function Dish([name, cookingTime]) { return <h1>{name} {cookingTime}</h1>; }
b) function Dish({name, cookingTime}) { return <h1>{name} {cookingTime}</h1>; }
c) function Dish(props) { return <h1>{name} {cookingTime}</h1>; }
d) function Dish(...props) { return <h1>{name} {cookingTime}</h1>; }
26. What is the difference between the click behaviors of these two buttons (assuming that this.handleClick is
bound correctly)?
handleChange(e) {
this.setState({[e.target.id]: e.target.value })
}
a) a computer property name c) a dynamic key
b) a JSX code string d) a set value
29. How do you invoke setDone only when component mounts, using hooks?
function MyComponent(props) {
const [done, setDone] = useState(false);
4
React JS
d) useEffect(() => { setDone(true); }, [done, setDone]);
30. What value of button will allow you to pass the name of the person to be hugged?
render() {
let name = "kitteh";
let button = // Missing Code
return button;
}
}
a) <button onClick={(name) => this.hug(name)>Hug Button</button>
b) <button onClick={this.hug(e, name)}>Hug Button</button>
c) <button onClick={(e) => hug(e,name)}>Hug Button</button>
d) <button onClick={(e) => this.hug(name, e)}>Hug Button</button>
5
React JS