React Native Flashcards
components
small, isolated code blocks to determine render. When data changes, React updates+re-renders.
React component class/type, parameters/properties(props),
a component which accepts props and returns a view hierarchy, displayed via its render().
render()
description of what to see on screen; React takes, then displays result
equivalent of JSX below in JS: <div> <h1>Shopping List for {props.name}</h1> <ul> <li>Instagram</li> <li>WhatsApp</li> <li>Oculus</li> </ul> </div>;
React.createElement(“div”, {
className: “shopping-list”
}, React.createElement(“h1”, null, “Shopping List for “, props.name), React.createElement(“ul”, null, React.createElement(“li”, null, “Instagram”), React.createElement(“li”, null, “WhatsApp”), React.createElement(“li”, null, “Oculus”)));
how to respond to click in button?
pass in function for onClick prop.
{this.props.value}
=>
“arrow function”; lambdas
(param1, param2) => block
; returnValue
super
whenever defining constructor of subclass, call super(props)
if you change state in component’s render(), …
React will re-render when state changes
to change state, use
this.setState({comment: 'Hello World!'});
not
`this.state.comment = ‘Hello World!’
state where?
lift state up
state privacy
state is private to component which defined it
controlled components
components where the render’s properties are fully set by props
function components
for components that only render, replace render() with function
ternary JS
var = ? “isTrue” : “isFalse”;
mental model:
we build from components.
components take in props
components with state, initialize state, and change state thru functions.
state is private to a component, but can pass state to child components.
children can’t change parent’s state, but can be given handlers by parents, which they call, which leads a parent to affect that parent’s state.
render() in a component returns components that make up that component
can replace render with function that returns same as render
=> is lambda, where (params) => return+exec_block