React.js: Short Answer _ OLD (Pluralsight Course)
What is JSX?
An HTML-like language that compiles to JavaScript.
What is the virtual DOM?
An abstraction over the DOM that performs in-memory comparisons.
What is a controlled element?
An element whose value is being controlled by a *component's state*
Why is React inherently more flexible than many popular competitors?
-- it's a library -- it's not opinionated
What does a react component represent?
A *piece of user interface*
What is a controller view?
A component that manages state and passes it down to children via props.
What is an action creator?
A function that returns an object with a *type* property and some optional data (*payload*)
What is a thunk?
A function that returns another function to delay execution
What is a reducer?
A function that takes state and an action and returns state.
How do you create a centralized header in React?
Compose the header in the *top level component*
What is the DefaultRoute component useful for?
Declare the route to load when the base url is requested.
What is the willTransitionTo static function useful for?
Determines if the requested page may be navigated to
T or F: *this.setState* is always synchronous.
FALSE - it is *always asynchronous*
T or F: An onClick hanlder for a child component should be passed to it as a prop from the parent component.
FALSE - onClick or onChange handlers are functions that should be housed in the child component and from within that you should call relevant function (in the parent) that you want to execute upon click/change.
What is the mapStateToProps function for?
It declares what state to provide on props
What is the benefit of React's virtual DOM?
It improves performance by minimizing DOM changes.
Why is prop validation useful?
It tells other developers what data a given component expects.
What library does Enzyme use behind the scenes to provide a virtual, in-memory DOM?
JSDOM
How are routes defined in React Router?
JSX
To handle async in Redux, what do you need to add to your store?
Middleware
T or F: A react component renders based on *props* and *state*.
TRUE
T or F: It is not a good idea to introduce a new *state element* when that element can be computed from other elements.
TRUE
T or F: In React you use plain Javascript for looping and conditionals.
TRUE - as opposed to a template-heavy approach (i.e. EJS)
T or F: A child component can never send a prop back to the parent component.
TRUE - hence *unidirectional flow*
T or F: Presentation Views / Components should mostly consist of JSX markup and not a lot of logic or data/state.
TRUE - they should receive all their data via props from parent controller view components.
Why are propTypes useful on reusable components?
They programmatically convey expectations about data passed to props.
Why does React typically require a build step?
To transpile JSX to Javascript
How do you test a React component that's connected to Redux?
We exported the raw component and tested it instead
What is Redux?
an open-source application state container
What lifecycle function is recommended for initially populating forms?
componentWillMount
Which lifecycle function is useful for initializing your component's data?
componentWillMount
What is the declarative way to render a dynamic list of components based on values in an array?
map array method
What npm package did we use to run parallel processes?
npm-run-all
What pattern does React use for handling data flows?
one-way binding
How does React Router make URL params accessible to components?
props
What mechanism is recommended for passing data down to child components in React?
props
Where should mutable data for React components be stored (when using Flux)?
state
With Redux, why are PropTypes useful?
they provide runtime warnings in development
What is the advantage of hash URLs?
they work on all browsers
What function is used to change the state of a class component?
this.setState
With Redux what property is required on all actions?
type
What are some Cons of using React with Redux?
with Redux, you are losing the ability to re-use your components as they are no longer self-contained
What happens if you don't create a change handler for controlled components?
No input is accepted
What is the primary technique for passing data out of a React component?
Pass the data to a function passed in as a prop
What can we do if components A and B are siblings and they require access to the same state element?
Place the state in the parent component of A and B
What React feature is disabled when built in production mode?
PropType validation