React - React Native
React - React Native
Facebook Platform
Developer Training
PUWANDI M ADITYO PRATOMO
Head of Technology Froyo Story Chief Academic Froyo Framework
[email protected] [email protected]
Please tell us about you
- Your name?
- OS
- Which Progaming Language
- NodeJs , NPM
- ReactJs & React Native
https://www.facebook.com/groups/DevCJakarta/
Topics
1. ReactJs
2. React Native
3. Facebook Analytics
JavaScript
Country: ‘Indonesia’
};
var foo = <div>Hello World</div>;
JSX
var foo = <div>Hello World</div>
ES6 Class
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
EXPRESSION
ReactJs Fundamentals / Framework Js
JSX Props Lifecycle Refs Router
1 2 3 4 5 6 7 8 9 10
Component 2
Components
● Everything is component
● Each component returns a DOM Object ( render function )
● It splits the UI into independent reusable pieces
● Each independent pieces is processed separately ( scoped )
● It can refer other components in output
● It can be further split into smaller components
Example React Component
<app></app>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<script>
var Hello = React.createClass({
render: function () {
return React.createElement('p', null, 'Hello world');
}
});
var App = React.createClass({
render: function() {
return React.createElement("div", null,
React.createElement('h1', {}, 'App Text'),
React.createElement(Hello, {}, '')
);
},
});
ReactDOM.render(React.createElement(App), document.querySelector("app"));
</script>
ReactJs Fundamentals / Framework Js
JSX Props Lifecycle Refs Router
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
States components
props props
● Heart of react components
components components
● Must be kept as simple as possible state state
● Determines components rendering props props
behaviour
components components
● The way to create dynamics and
state state
interactive components props
● Every UI component, reflects the
app state components
state
Example state
class App extends React.Components {
constructor (props) {
super (props)
this.state = {
counter: 1
}
}
render () {
return (
<div>
<button onClick={this.setState({counter: this.state.counter++})}>
Increment
</button>
{this.state.counter} // 1, 2, 3, 4, 5
</div>
)
}
}
ReactJs Fundamentals / Framework Js
JSX Props Lifecycle Refs Router
1 2 3 4 5 6 7 8 9 10
getDefaultProps()
getInitialState()
componentWillMount()
render()
componentDidMount
shoudComponentUpdate()
componentWillUpdate()
render()
componentDidUpdate()
Props Change Phase
componentWillReceiveProps()
sholdComponentUpdate()
componentWillUpdate()
render()
componentDidUpdate()
Unmounting Phase
ComponentWillUnMount()
1 2 3 4 5 6 7 8 9 10
return (
<a href="#" onClick={handleClick}>
Click me
</a>
);
}
Passing Argument in Event Handler
class LoggingButton extends React.Component {
handleClick(something) {
console.log('this is:' + something);
}
render() {
// This syntax ensures `this` is bound within handleClick
return (
<button onClick={(e) => this.handleClick(‘Event click’)}>
Click me
</button>
);
}
}
Lab Time
$ npm install -g create-react-app
$ create-react-app my-app
$ cd my-app
$ npm start
Follow instructions
https://gitlab.com/froyo-framework/facebook-react/blob/master/my-app/lab.md
$ cd reactTraining
$ npm start
https://gitlab.com/froyo-framework/facebook-react/tree/master/myReact
Build file
Build result
Creating Mobile App using
React Native is fun and more
productive
Creating Mobile App using
React Native is fun
Before
1. Set breakpoint
2. Highlight variable
3. Start inspecting
Sudo npm install -g react-devtools
1. react-native run-android/run-ios
2. react-devtools
Reactotron
https://github.com/infinitered/reactotron
Introducing Facebook Analytics
● Build better experiences
● Get valuable insight automatically
● Re-engage and grow your audience
What makes Facebook Analytics unique
● Deep, rich demographics data
● Accurate because it’s based on
Facebook Profile
● Included by default and
automatically available
● No dependence on Facebook
Login
The Facebook Analytics value proposition
● Aggregated demographic from Facebook
● Support for mobile, web, Messenger, Pages & physical stores
● Integrated with Facebook Ads tools
● Free to use
○ Products that offer all of these features are not usually free
○ Other free products don’t offer all of these advanced features
● Not only for Facebook insights
● Does not require Facebook login
Include the Facebook SDK for JavaScript
window.fbAsyncInit = function() { (function(d, s, id){
FB.init({ var js, fjs = d.getElementsByTagName(s)[0];
appId : '{your-app-id}', if (d.getElementById(id)) {return;}
xfbml : true, js = d.createElement(s); js.id = id;
version : 'v2.10' js.src = "https://connect.facebook.net/en_US/sdk.js";
}); fjs.parentNode.insertBefore(js, fjs);
FB.AppEvents.logPageView(); }(document, 'script', 'facebook-jssdk'));
};
See result in the Dashboard
Thank You