React Basics Flashcards
How do you create a new React app?
in command line:
mkdir FolderName
cd FolderName
npm init
How do you add a new module to your React app?
in command line:
npm install modulename –save
How do you create a server for your React app using the express module?
//create file under root directory server.js //in file server.js var express = require('express');
var app = express();
app.use(express.static(‘public’));
app.listen(3000, function () {
console.log(‘Express server is up on port 3000’);
});
What argument does require(‘’) take?
The name of the module in a string //example //this gives us access to the entire express api var express = require('express');
What does this line of code in in server.js? var app = express();
Creates a new app that has access to the entire express library
How do you tell your React app which folder to user on the server?
app.use(express.static('public')); //express.static('') tells the server which folder it will use
What does app.listen() do and what two arguments does it take?
- It starts the server
- 1. port name 2. a function that will be called when the server runs
What 2 things does the Babel library do for your React app?
- It allows you to use ES6 features for web browsers even if the browser does not include these features, Bable will compile them for you
- It converts JSX to javascript
What is the react-dom library used for?
It is used applications in a web enviornment
How do you run the server for your React app?
node server.js
What are React components?
Building blocks for your regular app’s UI
What is the common naming convention for React components?
//first word is capitalized the rest are camelcase //e.g. ReactComponent
What argument does the React.createClass() function take and what does it do?
- it takes an options object
2. it describes the behavior of the class
What is the only thing required of a react component method?
render: function() {
return();
}
What syntax does the return(); method take in this render?
render: function() {
return();
}
jsx