react Flashcards
react: In jsx, to write a css class attribute, you must write
className=”cssClass”
react: A component “mounting” means
it is rendering for the first time
react: The three mounting methods that get called in order when you call ReactDOM.render() are
componentWillMount: right before the component renders. You CAN call this.setState() in this. Being deprecated, so don’t use.
render: the render function runs and injects the JSX
componentDidMount: right after the render function runs. Usually used to make API call for initial data, can use constructor. Also used to
react: componentDidMount only gets called
AFTER the very first rendering of a component. Using set interval to run ReactDOM.render() again will not retrigger it.
react: componentWillReceiveProps will only get called if
a component is being passed in props
react: componentWillReceiveProps automatically gets passed one argument which is
an object called ‘nextProps’ which is the value of the prop that will be passed in
react: componentWillReceiveProps is an opportunity to
do something based on the new props a component is going use before render
react: files with jsx written in them must be
compiled before sent to browser
react: If a JSX snippet takes up multiple lines, you must
wrap it in parentheses.
react: JSX must be
wrapped in one outermost element.
react: ReactDOM.render() takes the arguments
component and location to inject it
ie
ReactDOM.render(-h1>Hello world-/h1>, document.getElementById(‘app’));
react: To render a JSX expression into the template, type
ReactDOM.render(-h1>Hello world-/h1>, document.getElementById(‘app’));
react: if you call
ReactDOM.render(hello, document.getElementById(‘app’));
and then again
ReactDOM.render(hello, document.getElementById(‘app’));
it will
do nothing because react will only render the same component in the same location again if it has changed
react: In JSX, self closing tags like input and img must
have a closing slack ie img />
react: To evaluate code inside of JSX,
wrap it in {} ie -h1>{2 + 3}-/h1> and the return will be rendered
react: The JSX in your file can access
all the variables in the environment
const theBestString = ‘tralalalala i am da best’;
ReactDOM.render(-h1>{theBestString}-/h1>…
react: event listeners (like onclick) in JSX must
be written in camelCase
onClick={funcName}
react: To manipulate the element that sent an event, use
function functionName(e) { const element = e.target }
ie the -img> src will change.
function changeImage(e) { e.target.setAttribute('src', 'https://url.com'); }
react: in JSX, you cannot
write if statements in the {} braces
js: To write a ternary, type
x > 10 ? y : z
js: To write a conditional using &&, type
x > 10 && functionName()
note: It is the same as a ternary but with no else
React: JSX can be rendered even if it is a
list of JSX objects.
const liArray = [ -li>item 1-/li>, -li>item 2-/li>, -/li>item 3-/li> ];
-ul>{liArray}-/ul>
React: To use map to make a list of JSX objects, type
const myJSXArray = myArray.map((item, key) => -li key={key}>{item}-/li> );
React: The steps for rendering JSX are
A JSX element renders.
The entire virtual DOM updates.
The virtual DOM “diffs,” comparing its current self with its previous self.
Part of the real DOM updates.
The screen looks different than it used to.