React All Flashcards
What is react?
front end framework for Javascript
Front end framework
standardized way of creating and deploying parts of a web applications
3 features of React
- declarative, component-based, learn once, write everywhere
Declarative programming
describes what to accomplish and leaves how to do the action up to the program
imperative programming
scribe each step/action a program should make and how the program should do the actions step by step
what are components
building clocks of our web page that handles their own data and UI logic
why is react a learn once and write everywhere program
works in different environments and easy to learn other react languages
how do you launch react project
npm start
what is babel
transpiler that converts modern JS and custom code like JSX into compatible JS
what is webpack
bundler that takes all our work along with any required dependecy code and packages it all together in a transferable bundle
ESLint
linting and code analysis functionality to help improve code and reinforce best practices
JS packages
a file or set of files full of existing, reusable code
what is npm
package manager for Node that helps organize JS packages in relation to our work
can you use packages to build other packages
yes
what is package.json
file that tells you and npm what packages are required for a specific JS application
what command reads the packages.json dependency’s
npm install
where does npm install download the packages from
npmjs.com
node_modules
local environment creates this folder to hold downloaded packages
npm install package name
how to add a specific package
npm init
creates package.json and includes specific content to include in the file
npm test or learn test
runs the test script found in package.json
render
method that comes from react-dom package
what 2 arguments does render take
react component to render
dom element where we want the component to be rendered
App.js
top level that cantains app compoents
how do you pull content form node_modules folder
import
what creates a tree of dependencies by exporting component
export
what lets you split the UI into independent resuable pieces and think about each in isolation
components
what 2 things does components help with
help with functionality and presentation of code
what is boilerplate code
sections of code that are repeated in multiple places with no variations
what is the end goal of components
contain a snippet of code that describes what they should render to the DOM
how do you name components
declarative word that is capitalized
syntax for creating component
(function)
function Comment (){
return (
<div> comments</div>
)}
(arrow)
const Comment = () => <div> comment</div>
syntax for creating class components
class Comment extends React.Component {
render() {
return <div> comments </div>}
}
minimum component requirements
- must be a function that starts with a capital letter
- must return JSX
module code
code that is separated into segments (modules) where each file represents a feature or specific functionality
why use module code?
-stricter variable scope
-single responsibility
-easier to navigate
-easier to debug
- produce clean and dry code (reusable)
what does import/export variable allow us to do?
define variables in one file and access them in another file
export default
export ONE variable from file to be used in another file
export default syntax
export default ComponentName; (goes at end of file)
Named exports
export multiple variables from a file
named exports syntax
export{varaible1, variable2}
or
directly next to variable
export function variable1 (){
}
import
takes in the variables that have been exported and adds them to other files
syntax for importing multiple variables
import* as variableBeingCalled from “relative path”
syntax for importing specific variables
import{variable} from “relative path”
syntax for importing node_modules
import React from “react’
what is JSX
syntax extension of JS that creates a special/ productive marriage of HTML and JS
what is JSX short for
Javascript XML
6 characteristics of JSX
- is not a string
- is the return value of a function component
- contains JS in {}
- works with expressions not statements (can’t use if (){})
- can render other components in a component
- component must return one JSX element
props
parameter in components that pass information from parent to child component
props syntax
function parentFunction (){
return <ChildComponent text = “Hello”}
the prop passed to childComponent is Hello
what data types can props take
any data types (number, function, boolean, etc) execept strings
how are props accessed
assessed in child component via an object that is passed into our component function as an object
default value
assigns value to prop if component doesnt receive prop value from parent
what is used to iterate a list of array to component object
.map
what must you add when using .map
key
what is key value
unique value associated with each element in the array (id, name, etc. that dont repeat in array)
you can use index as a key
false
what is the event handler prefix in react
on (onClick, onSubmit, etc)