SlideShare a Scribd company logo
Real World Functional
Programming
reason-react
Functional Programming for React developers
@keirasaid
Linux conf-2018-fp-miniconf-slideshare
React.js Reason-ReactReasonML FinStart
The State of JS 2017
ContentContainer
Button
Header
ContentContainer
Header
Button
AnotherContainer
Header
Button
<button>
{this.props.buttonText}
</button>
<h1>{this.props.headerText}</h1>
ContentContainer.propTypes = {
headerText: PropTypes.string.isRequired,
buttonText: PropTypes.string.isRequired,
};
Unidirectional
Data-flow
Stateful component
Stateless component
Stateless component
<button>
{this.props.buttonText}
</button>
<h1>{this.props.headerText}</h1>
ContentContainer.propTypes = {
headerText: PropTypes.string.isRequired,
buttonText: PropTypes.string.isRequired,
};
Unidirectional
Data-flow
Stateful component
Stateless component
Stateless component
<button>
{this.props.buttonText}
</button>
<h1>{this.props.headerText}</h1>
render() {
return (
<ContentContainer>
<Header headerText=“My Header” />
<Button buttonText=“Click Me” />
</ContentContainer>
);
}
JavaScript
https://wiki.haskell.org/The_JavaScript_Problem
1. JavaScript, the language, has some issues that
make working with it inconvenient and make
developing software harder :
lack of module system (only pre-Ecmascript 2015),
weak-typing,
verbose function syntax (pre-Ecmascript 2015),
late binding,
finicky equality/automatic conversion,
‘this’ behaviour,
and lack of static types.
2. We need JavaScript
Linux conf-2018-fp-miniconf-slideshare
Linux conf-2018-fp-miniconf-slideshare
Linux conf-2018-fp-miniconf-slideshare
+ =>
React.js Reason-ReactReasonML FinStart
Linux conf-2018-fp-miniconf-slideshare
Linux conf-2018-fp-miniconf-slideshare
Syntax
JavaScript Reason OCaml
“Hello Linux Conf 2018!” Same as JS Same as JS
‘Hello Linux Conf 2018’ Must use double quotation marks Must use double quotation marks
“Hello” + “Linux Conf” “Hello” ++ “Linux Conf” “Hello” ^ “Linux Conf”
Syntax
JavaScript Reason OCaml
true, false Writes like JS, compiles differently Writes like JS, compiles differently
!true Writes like JS, compiles differently not true
||, &&, <=, >=, <, > Writes like JS, compiles differently Writes like JS, compiles differently
Syntax
JavaScript let greaterThan = (num1, num2) => num1 > num2;
Reason let greaterThan = (num1, num2) => num1 > num2;
Bucklescript var greaterThan = Caml_obj.caml_greaterthan;
Syntax
JavaScript
let x = 5;
x = x + 1;
Syntax
JavaScript Reason OCaml
let x = 5;
x = x + 1;
let x = ref(5);
x := x^ + 1;
let x = ref 5
x := ((!x) + 1)
OCaml Syntax
OCaml Semantics
Bytecode Native
https://
spyder.wordpress.com/
2017/05/14/ocaml-to-
javascript-buzzwords/
OCaml Syntax
OCaml Semantics
Bytecode Native
https://
spyder.wordpress.com/
2017/05/14/ocaml-to-
javascript-buzzwords/
js_of_ocaml
https://
spyder.wordpress.com/
2017/05/14/ocaml-to-
javascript-buzzwords/
OCaml Syntax
OCaml Semantics
Bucklescript
Linux conf-2018-fp-miniconf-slideshare
https://
spyder.wordpress.com/
2017/05/14/ocaml-to-
javascript-buzzwords/
Reason Syntax
OCaml Semantics
Bucklescript
React.js Reason-ReactReasonML FinStart
+ =>
Because it’s
reasonably easy.
Linux conf-2018-fp-miniconf-slideshare
Learning and chunking
• Miller, G.A. (1956) The magical number seven, plus or minus
two: some limits on our capacity for processing information.
Psychol. Rev. 63, 81–97
• Gobet, F., Lane, P. C. R., Croker, S., Cheng, P. C. H., Jones, G.,
Oliver, I., & Pine, J. M. (2001). Chunking mechanisms in human
learning. Trends in Cognitive Sciences, 5(6), 236-243.
• Guida, A., Gobet, F., Tardieu, H., & Nicolas, S. (2012). How
chunks, long-term working memory and templates offer a
cognitive explanation for neuroimaging data on expertise
acquisition: A two-stage framework. Brain and Cognition,
79(3), 221-244. doi: 10.1016/j.bandc.2012.01.010
• Syntax
• Workflow
• React mental model
Key similarities
Immutable
by default
NPM /
Yarn
Refmt
Rtop
Static
Typing
ReasonRouter
NPM /
Yarn
JavaScript
Console
Prettier
EsLint
ReactRouter
Immutable.js
Flow
NPM /
Yarn
NPM /
Yarn
Included
included in
Browser
Included in
toolchain
language
feature
Includedin syntax
Dependency
Dependency
Dependency
Dependency
Immutable
by default
Dependency


npm install -g bs-platform
then
yarn create react-app my-app --scripts-version
reason-scripts
or
bsb -init my-react-app -theme react
Linux conf-2018-fp-miniconf-slideshare
Linux conf-2018-fp-miniconf-slideshare
Linux conf-2018-fp-miniconf-slideshare
React mental model
Key similarities
React Component Lifecycle ReasonReact Component Lifecycle
componentDidMount() didMount
componentWillReceiveProps() willReceiveProps
shouldComponentUpdate() shouldUpdate
componentWillUpdate() willUpdate
componentDidUpdate() didUpdate
componentWillUnmount() willUnmount
componentWillMount() not implemented - use didMount
props => labeled arguments
React mental model
{this.props.someProp}
example.js
<Example someProp=“hello!” />
React mental model
<Example someProp=“hello!” />
example.re
let make(~someProp, _children) {
...component,
render /* etc */
};
let make(~someProp=?, _children) {
...component,
render /* etc */
};
example.re
<Example someProp=?someDataVariable />
Optional argument
let make(~someProp=“hi!”, _children) {
...component,
render /* etc */
};
example.re
<Example someProp=someDataVariable />
Default argument
stateless & stateful
components
React mental model
ReasonReact.statelessComponent
ReasonReact.statefulComponent
ReasonReact.statelessComponent
ReasonReact.reducerComponent
type state = { counter: int }
type action =
| DoSomething
| DoSomethingElse
| DoAnotherThing
type action =
| Click
| Toggle;
let make = (_children) => {
...component,
initialState: () => { count: 0 },
reducer: (action, state) =>
switch(action) {
| Click => ReasonReact.Update({…state etc
| Toggle => ReasonReact.Update({…state
type action =
| Click
| Toggle;
let make = (_children) => {
...component,
initialState: () => { count: 0 },
reducer: (action, state) =>
switch(action) {
| Click => ReasonReact.Update({…state etc
| Toggle => ReasonReact.Update({…state
reducer: (action, state) =>
switch(action) {
| Click => ReasonReact.UpdateWithSideEffects(
{…state, count: state.count + 1}),
(self => self.send(DoSomething)
| Toggle => ReasonReact.Update({…state
Intermission
Linux conf-2018-fp-miniconf-slideshare
ship it
Inside the Magic 8 Ball App
Using a React component
Fetching data from an API
Option type pattern matching
Using a React component in ReasonReact
buttonWrapper.re
Button.js
Button.js
ButtonWrapper.reReasonReact.wrapJsForReason
ButtonWrapper.reReasonReact.wrapJsForReason
ButtonWrapper.reReasonReact.wrapJsForReason
Linux conf-2018-fp-miniconf-slideshare
Using a Reason component in React
Using Bucklescript with APIs
MagicEightBall.re
yarn add -D bs-fetch bs-json
Linux conf-2018-fp-miniconf-slideshare
{
magic: {
question: "Will I ever let you down?",
answer: "Reply hazy, try again",
type: "Neutral"
}
}
Linux conf-2018-fp-miniconf-slideshare
Linux conf-2018-fp-miniconf-slideshare
Using Pattern Matching
App.re
type state = {
data: option(MagicEightBall.data),
/ * …other state */
}
switch (state.data: option(MagicEightBall.data)) {
| Some(data) => <Answer data=data />
| None => <div><img src=loading /></div>
};
render: ({state, handle, send}) => {
let answer =
React.js Reason-ReactReasonML FinStart
“At the language level, it has features that we’ve previously had to
bolt on top of the JavaScript such as allocation-less named
arguments, prop types, and more. In short, it is the best way to
take React to the next level - unlocking far better user
experiences and fast-loading applications
Jordan Walke
(creator, React and Reason,
Reactiflux Discord Channel Q & A, 2017)
JavaScript and HTML - I can build things!
React - I can reuse my things!
ReasonReact - I can reuse my React things more safely!
All Functional Programming
https://jaredforsyth.com/2017/07/05/a-reason-react-tutorial/
https://jamesfriend.com.au/a-first-reason-react-app-for-js-developers
https://spyder.wordpress.com/2017/05/14/ocaml-to-javascript-buzzwords/
http://blog.klipse.tech/reason/2017/10/17/externals-js-ffi-reason.html
http://2ality.com/archive.html?tag=reasonml
Join the community on
http://discord.gg/reasonml 
FIN
join the community on
http://discord.gg/reasonml 

More Related Content

Similar to Linux conf-2018-fp-miniconf-slideshare (20)

PDF
Introduction to ReasonML
Riza Fahmi
 
PDF
Integrating React.js with PHP projects
Ignacio Martín
 
PDF
React.js workshop by tech47.in
Jaikant Kumaran
 
PDF
Nik Graf - Get started with Reason and ReasonReact
OdessaJS Conf
 
PPTX
Adding a modern twist to legacy web applications
Jeff Durta
 
PDF
MeetJS Summit 2016: React.js enlightenment
Artur Szott
 
PDF
An Overview of the React Ecosystem
FITC
 
PDF
Reasonable app development
Arnar Þór Sveinsson
 
PDF
Mastering-Reactjs-Your-Path-to-Web-Development.pdf
sagarheddurshettyvio
 
PPTX
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PrathamSharma77833
 
PPTX
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
PDF
ReactJS
Kamlesh Singh
 
PPTX
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
PDF
Intro to react_v2
Feather Knee
 
DOCX
Vi INFOTECH react syllabus
ViINFOTECH
 
PDF
react-slides.pdf
DayNightGaMiNg
 
PDF
react-slides.pdf gives information about react library
janet736113
 
PPTX
Better web apps with React and Redux
Ali Sa'o
 
PDF
We Are Developers - Modern React (Suspense, Context, Hooks) - Roy Derks
Roy Derks
 
PPTX
Fullstack JS Workshop
Muhammad Rizki Rijal
 
Introduction to ReasonML
Riza Fahmi
 
Integrating React.js with PHP projects
Ignacio Martín
 
React.js workshop by tech47.in
Jaikant Kumaran
 
Nik Graf - Get started with Reason and ReasonReact
OdessaJS Conf
 
Adding a modern twist to legacy web applications
Jeff Durta
 
MeetJS Summit 2016: React.js enlightenment
Artur Szott
 
An Overview of the React Ecosystem
FITC
 
Reasonable app development
Arnar Þór Sveinsson
 
Mastering-Reactjs-Your-Path-to-Web-Development.pdf
sagarheddurshettyvio
 
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PrathamSharma77833
 
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
ReactJS
Kamlesh Singh
 
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Intro to react_v2
Feather Knee
 
Vi INFOTECH react syllabus
ViINFOTECH
 
react-slides.pdf
DayNightGaMiNg
 
react-slides.pdf gives information about react library
janet736113
 
Better web apps with React and Redux
Ali Sa'o
 
We Are Developers - Modern React (Suspense, Context, Hooks) - Roy Derks
Roy Derks
 
Fullstack JS Workshop
Muhammad Rizki Rijal
 

Recently uploaded (20)

PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Ad

Linux conf-2018-fp-miniconf-slideshare