8 Hours
I want to create interactive UIs more easily and with less code than jQuery.
React is complex, but one reason it is awesome is that you can build a component with it's own html, css, and js characteristics - for example, a styled list item - and that's the only time you have to write it. You can use it whenever you want by calling the component name you made up - - anywhere you like in your project. Another reason is because you see changes instantly as you develop and as your app runs. No more refreshing!
Facebook created React as a framework to create reusible components, like posts or comments, and allow the user see updates instantly. Instagram and Airbnb use it too.
Participants will be able to:
- Explain the Pros and Cons of using React instead of other tools, like jQuery.
- Create a simple React Component.
- Hook up user actions to state changes in the UI.
- Why React?
- What is JSX and why is it different than HTML?
- Specifics about co-locating markup with logic in code.
You will spend the day working through these materials.
- Introduction to React (video)
- Learn React in 5 minutes (video)
- Techtonica React slides
- Building your first component in React.js | Pluralsight (video)
- Work through this React tutorial
- React JS & Tree Reconciliation
- CodePen for Hello World Example
- CodePen Greeting with Input Example
- CodePen for Counter Example
- CodePen for List - Rendering using a loop in React
- What is React?
- React is a library for creating User Interfaces.
- This means it is used for creating what some refer to as the "view layer" of an application.
- JSX adds to our JavaScript to allow for HTML-like markup in JavaScript.
- Show Hello World example, plus expanded example.
- Example for appending to a list in jQuery vs. the same in React.
- JSX tag names for components must match up with component names, both in spelling and case.
- In render functions, don't forget to return JSX.
- Don't forget to specify both arguments in ReactDOM.render function.
- Don't forget
this
when working within a React class. Examples:this.state.thing
- Don't forget that variables in JSX must be enclosed in brackets and don't forget number 4. Example:
<div>Hello {this.state.thing}</div>
- The event system in React uses attributes you are likely familiar with from HTML, but they are written using camelCase. Example:
<button onClick={function() { alert('hello!') }}>I am a button</button>
- The term 'ReactJS' is commonly used to clarify that it's a javascript framework; however, 'React' is its official name.
-Importing & Exporting with React
- Remove from list
- Putting two counters on the page
- Append to list using React
Have apprentices summarize to each other, make a cheat sheet, take a quiz, do an assignment, or something else that helps assess their understanding.
- Make sure everyone had an opportunity to complete the practice exercises.
- Give ample opportunity for follow-up conversations.
- Lead into "Why React?" by asking follow-up questions and checking for understanding of key concepts from the "Wrap Up" section.
- It simplifies creating UIs, especially when compared to other libraries, such as jQuery.
- It is easier to read, and as a result is also easier to maintain.
- It encourages creating reusable components that you use everywhere, rather than recreating things everywhere.
- While it is a bit of a departure from prior approaches, co-locating markup with JavaScript leads to more easily understood code.
- It cuts down on the amount of code you have to write. In some instances, things that once took hundreds of lines of code can now be written with only a few dozen lines or less.
- Features unique to ES6: https://github.com/lukehoban/es6features