Intro Stuff Flashcards
What are common patterns for doing conditionals in XML?
- Ternary operator inline
- Use the ‘&&’ operator, when there’s no ‘else’ condition.
- Define a variable in an if/else above in the render() method, and then display that variable.
How do you take advantage of booleans in Javascript?
You can write variables and then set them equal to the condition. Then use the fact that that variable will be either truthy or falsey later on.
How do you loop in JSX?
Use array.map(fn)
class Messages extends React.Component { render(). { const msgs = [ {id: 1, text: "Greetings!!"}, {id: 2, text: "Goodbye!"}, ]; return ( <ul> { msgs.map(m => <li>{m.text}</li>) } </ul> ); } }
How can you make your JSX variables considerably shorter in your return statment?
Use destructuring.
class Friend extends Component { render() { const { name, hobbies } = this.props; return() } }
How does map work?
It returns the result of the callback function for each item in the array.
How do you put variables into a map return statement?
Put additional ‘{ }’ around the variables.
How do you handle events with state?
- Initialize state
- Constructor
- Super
- Set ‘this.state’
- Use the state key inside of return function.
- Define a function inside the class that changes the state. handleClick(e)
- Add the function on the event handler inside of return
- this.handleClick
- Bind ‘this’ inside the constructor
- this.handleClick = this.handleClick.bind(this);
What things do you put inside the class?
Render
Default props
Constructor
event functions
What’s the shortcut for initializing state?
Leave the constructor out and just put something like this in the class:
state = {clicked: false};
What’s the shortcut for handling events and updating state?
Inside of the class call:
handleClick = e => {
this.setState({clicked: true});
};
Duplicate line up/down
Shift + Option + Up / Shift + Option + Down
Move Line up/down
Option + Up / Option + Down
Multi-select selection
Command + D (to select next occurrence(s) after you make an initial selection)
Multi-select Cursor
Option + Click
Toggle line comment
Command + /