2. What is this about?
• This workshop wont help you be a better coder
• This workshop wont make you an expert in React
Native
• The UI of the slides wont get better over time
3. Brief intro
• Hello, I am Stacy
• I work at Govtech,
Government Digital Services,
DCUBE
• https://imstacy.com
• https://github.com/stacygohyunsi
• https://medium.com/@stacygoh
20. “Diffing” algo
By comparing the new virtual DOM with the earlier
version, React finds out exactly which virtual DOM
objects have changed
Now, React smartly updates only those objects on the
real HTML DOM.
27. JSX
• JSX stands for JavaScript XML
• A templating language
• Embed any javascript inside of a JSX template by
wrapping it in curly braces (these: {})
28. JSX
const element = <h1>Hello, world!</h1>;
function formatName(user) {
return user.firstName + ' ' +
user.lastName;
}
const element = (
<h1>
Hello, {formatName(user)}!
</h1>
);
33. Example of Immutability
this.state= {
passengers: [
'Simon’,
'Taylor’
]
}
Suppose we want to add a passenger called Vincent to the
passengers array…
39. Create copies of the objects in this.state and
manipulate the copies
Map, filter and concat => non-destructive array
methods => methods that will return a new object
or array with the desired mutations
Example of Immutability
41. AngularJS
Change model -> modifies view
Change input field in view -> modifies model
Lead to cascading updates
Two way binding vs
Unidirectional data flow
46. React commands
• npm start - Starts the test runner
• npm run build - turn it into a smaller (“minified”)
version that the browser can read
• npm test - test via Jest
• npm run eject - copies build dependencies,
configuration files and scripts into the app directory
(irreversible)
47. React Main Components
• Babel (for JSX)
• Webpack (a module bundler which takes modules
with dependencies and generates static assets by
bundling them together)
• Testing (Jest)
48. Index.js
import React from 'react';
import ReactDOM from ‘react-dom'; //
ReactDOM has one function in particular
that we want to use: render()
import App from './App';
import registerServiceWorker from './
registerServiceWorker';
import './index.css';
ReactDOM.render(<App />,
document.getElementById('root'));
registerServiceWorker();
51. React components must only return a SINGLE JSX
node at its root, so it’s very common to wrap up your
components into a single div that might have multiple
children underneath it.
69. Common questions?
• How do I pass data up?
• You can pass the data up through a callback in
props, or use Redux
• What to learn next?
• ComponentWillMount, ComponentDidMount etc
• What UI Components to use with ReactJS?
• React-Bootstrap, Material-UI, React-strap
72. React Native Advantages
• JavaScript − Existing JavaScript knowledge
• Code sharing − Share most code on different
platforms
• Community − Community around React and
React Native is large
• Native Look and Feel
73. React Native Limitations
• Native Components − might need to write some
platform specific code
• Not even version 1 yet
76. Answer:
• Cordova: create HTML, style with CSS, and write
all the logic with JavaScript
• React-Native: Visual components (reusable UI
elements) are rendered as a native UI
78. Method 1: create-react-native-app through Expo
(to use use custom native modules, you have to eject)
Method 2: react-native cli
(for the braver souls and those who never die before)
Environment for React
Native
79. Method 1
• npm install -g create-react-native-app
• create-react-native-app my-native-app
• cd my-native-app
• npm start
• Download Expo App
• Scan the QR Code
80. Method 2
• npm install -g react-native-cli
• react-native init reactTutorialApp
• cd reactTutorialApp
• react-native start
• (start in a new terminal) react-native run-ios
• react-native run-android