React for Beginners Flashcards
Everything within React is not a model or a controller but a…
Component
A Component is similar to
Building your own HTML tags, which you can supply with a whole buncha information.
What 3 types of information can you pass to a component?
Props, State and Context
What one method does every single class within React need?
The Render method.
What does the Render method do within a React class?
It just kind of determines what DOM elements at the end of the day are put onto the page.
What’s the syntax if you just want to cherry pick one method from a package?
import { render } from ‘react-dom’ (The curly braces are what makes the magic happen)
How do you mount the app to a page?
You need an empty div within your index.html that you can mount to, and then within your index.js you need to render your primary component to it. Here is an example of that: render(, document.querySelector(‘#main’));
What do you need at the end of each class file?
An export statement - something like: export default StorePicker;
How do we write HTML within React?
With JSX - which isn’t required, but the other options of React.CreateComponent and such - they hurt and they make us sad.
What does one use instead of ‘class=mwuhmwuh’ when setting the class name of an HTML element?
we use className, cause React likes that.
What’s the rule on sibling elements within JSX?
They can’t returned. We have to return one element - it can have whatever the high hay it wants inside of it - but there must ultimately just be one element being returned.
How do we get around JSX only letting us return one element when we want to do some FlexBox or CSSGrid stuff?
mwuh mwuh - or if we import {Fragment} from React, we can have the clearner looking This avoids unnecessary divs all up in our DOM
What should we expect to be able to do soon instead of
<> >, as soon as Babel gets its act together.
How do we make comments within JSX?
{ /* yooo */ } - not just a //, and not an html comment , and event within our squirlies - not a //. Must be the block JS comments within squirlies
What’s the big stupid thing that makes people throw their computers when they get an unexplained error in regards to comments? The error message says something about an unexpected comma?
People try to put a comment above their Fragment or their parent element - which, in effect, is returning two sibling elements, which breaks everything. You often don’t think of a comment as an element - but it is.
How do you import CSS into a React app?
You can either do it inline, or you can put an import statement at the top, like import ‘./css/style.css’ People are ready to die on both sides of this decision. Meh.
Tell me about Props
They are similar to HTML attributes - and just like how an Image tag needs a src and an alt, or an Input tag needs the type attribute - we can pass our own custom attributes with our components. This is how we get data into a component from its parent.
State is where the data lives…
Props are how the data gets to work. They’re like the bus.
Other than not using already existing props, what are the rules about props?
None, man. Just name them whatever and call them with this.props.whatever.
In what way are props similar to an arguments object within a function?
They’re both just objects of data that were passed in when the component or method was called.
What’s the thing to remember when passing anything other than a string to a prop? (Such as a number or a boolean)
It has to be in curly “I’m doing some JS now” braces.
What do you do when you want to use a JS variable within JSX?
Put it in some of those curly braces man.
What does ‘this’ refer to when we’re rocking React?
The component instance. So this.props is the props object within the current component.
When you type $0 in React Dev Tools, what does it refer to?
What ever element is selected.
What does $1 in React Dev Tools terminal refer to?
The second to last item chosen. And $2 grabs the one before that, and I think so on (or maybe only up to 2?)
What does $r refer to within React Dev Tools?
The component instance. You can then open it up in DevTools and see everything in the object including what the props are set to.