React.js Flashcards
What is React?
Front-end javascript library that makes it easier to make user interfaces
Very popular in 2019
Benefits of React
Re-usability
Organization
Concise code
Scales well
Components
Contains its own html, css, js
Can update itself without affecting other components
Intro to Code Sandbox and Structure to the Module
Code Sandbox is a nice to use IDE on the browser that contains all the setup needed for coding
Intro to JSX and Babel
Every react html has a <div>
</div>
.render()
Inserts HTML into the website, through the javascript file/code
Arguments
1. What to show
Note: only takes 1 element
2. Where to show
In this case, document.getElementById(‘root’)
3. Callback
React creates JSX files
HTML code inside of a Javascript file
Babel
Javascript compiler inside of React module Takes any Javascript code and converts it into an equivalent Javascript code that can be read by any browser
Javascript Expressions in JSX & ES6 Template Literals
We can insert Javascript inside an HTML inside of a javascript
{}
Only values or expressions can be placed, not statements
JSX Attributes & Styling React Elements
In the JSX file, instead of using “class=”, we would have to use “className=”
HTML attributes for JSX must be camelCase
Inline Styling for React Elements
Even though it looks like HTML, it is not, it’s JSX
For inline styling, we need to pass in a javascript object
React Components (1)
Components can help us break down a large codebase into smaller ones, plus the benefit of reuseability
To create a React Component, create a function that has the naming convention in Pascal form
Create a new file with .jsx extension
React Components (2)
In the index.js file, import the .jsx file and use the component like how you would use an HTML element
Normally, React app’s in their index.js have an App component, which comprises of all of the UI
All the components will have their own .jsx file
And all the components will be organized into sub-directories
Javascript ES6 - Import, Export and Modules
export default
There can only be 1 default export for a .jsx file
Export multiple functions, values, objects, ….
export {}
import * as from “”
wildcard import is discouraged, as it reduces readability
Starting up a React app // React Props
Is a method to pass in parameters from JSX html to the React functions
We can also pass in functions as well
name, imageURL, tel, email are like parameters that get passed to Card, with all the parameters inside of props