SlideShare a Scribd company logo
1 of 42
Headless Drupal + ReactJS
Oleksandr Linyvyi
Drupal Developer, Adyax
oleksandr.linyvyi@gmail.com
Why Drupal?
Drupal is used only for few
things
โ€ข Data storage (Drupal DB basically)
โ€ข Data provider (Services)
โ€ข Serve single HTML page with React app
Frontend part is the
responsibility of React app
only
Why React?
React is used for
โ€ข Data fetching
โ€ข Data display
Basically it does all the UI stuff
React specific things
โ€ข Virtual DOM
โ€ข JSX
โ€ข Consequence - markup is mixed with JS
โ€ข And it is hard to get used to it ๏Š
โ€ข Also โ€“ a lot of 3rd
party libs may (and
should be) used
<Button color=โ€œgreen" borderSize={2}>
Click Me
</Button>
React.createElement(
Button,
{color: 'green', borderSize: 2},
'Click Meโ€˜
)
prevraschaetsโ€™a v
Babel
http://babeljs.io/
Babel is a JavaScript compiler.
function Item(props) {
return <li>{props.message}</li>;
}
function TodoList() {
const todos = [
'finish doc',
'submit pr',
'nag dan to reviewโ€˜
];
return (
<ul>
{todos.map((message) =>
<Item key={message} message={message} />
)}
</ul>
);
}
Smart / dumb components
โ€ข Dumb (presentational) โ€“ are concerned
with how things look
โ€ข Smart (container) โ€“ are concerned with
how things work
Redux
โ€ข Keeps application state in single place
โ€ข State is read only
โ€ข State transitions are predictable and
consistent
โ€ข Changes in state are made only by
dispatching an action
โ€ข And reducers describe how state is
transformed by actions
State
{
selectedNode: 1,
nodes: [
{
nid: 1,
title: 'Consider using Redux',
body: 'Lorem ipsum'
},
{
nid: 2,
title: 'Keep all state in a single tree',
body: 'Dolor sit amet'
}
]
}
Actions
{
type: 'SELECT_NODE',
nid: 2
}
Reducers
function selectedNode(state = null, action) {
switch (action.type) {
case 'SELECT_NODE':
return action.nid
default:
return state
}
}
Dispatching an action
store.dispatch({
type: 'SELECT_NODE',
nid: 2
})
New state
{
selectedNode: 2, // changed
nodes: [
{
nid: 1,
title: 'Consider using Redux',
body: 'Lorem ipsum'
},
{
nid: 2,
title: 'Keep all state in a single tree',
body: 'Dolor sit amet'
}
]
}
Package management
Where to search for packages?
โ€ข Npmjs.com
โ€ข Github.com
NPM is your tool:
$ npm install react react-dom --save
Some useful packages
โ€ข react, react-dom
โ€ข react-redux
โ€ข redux-thunk
โ€ข immutable
โ€ข reselect
โ€ข lodash
Demo app
โ€ข Load a list of nodes
โ€ข Display a list of clickable node titles
โ€ข Display node body on click on node title
Enable modules
Create a view
React part
Used packages
โ€ข React
โ€ข React-dom
โ€ข React-redux
โ€ข Redux-thunk
โ€ข Lodash
State
{
selectedNode: 1,
nodes: [
{
nid: 1,
title: 'Consider using Redux',
body: 'Lorem ipsum'
},
{
nid: 2,
title: 'Keep all state in a single tree',
body: 'Dolor sit amet'
}
]
}
Actions
{
type: 'STORE_NODES',
nodes: json
}
{
type: 'SELECT_NODE',
nid,
}
Reducers
function selectedNode(state = null, action) {
switch (action.type) {
case 'SELECT_NODE':
return action.nid;
default:
return state;
}
}
function nodes(state = [], action) {
switch (action.type) {
case 'STORE_NODES':
return action.nodes;
default:
return state;
}
}
Async action
export function loadNodes() {
return (dispatch) => {
return fetch('http://d8react.local/rest/nodes', {
credentials: 'include',
})
.then((response) => {
return response.json();
})
.then((json) => {
dispatch({ type: 'STORE_NODES', nodes: json });
})
.catch((error) => console.log(error.message))
}
}
import { connect } from 'react-redux';
import NodeList from 'NodeList';
const mapStateToProps = (state) => {
return { nodes: state.nodes }
};
const mapDispatchToProps = (dispatch) => {
return { onClick: (nid) =>
dispatch({ type: 'SELECT_NODE', nid })
};
};
export default connect(
mapStateToProps,
mapDispatchToProps)
(NodeList);
Node list (smart)
Node list (dumb)
import React from 'react';
export default (props) => (
<ul>
{props.nodes.map((node) => {
return <li
key={node.nid[0].value}
onClick={() => props.onClick(node.nid[0].value)}
>
{node.title[0].value}
</li>;
})}
</ul>
);
Node content (smart)
import { connect } from 'react-redux';
import _ from 'lodash';
import NodeContent from 'NodeContent';
const mapStateToProps = (state) => {
return {
node: _.find(state.nodes,
(node) => node.nid[0].value == state.selectedNode
)
}
};
export default connect(mapStateToProps)(NodeContent);
Node content (dumb)
import React from 'react';
export default (props) => {
return
!!props.node ?
<div>{props.node.body[0].value}</div> :
null;
};
All together
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import promiseMiddleware from 'redux-promise-middleware';
import { Provider } from 'react-redux';
import reducer from './reducers';
import { loadNodes } from './actions';
import NodeListContainer from './NodeListContainer';
import NodeContentContainer from './NodeContentContainer';
All together
const initialState = {
selectedNode: null,
nodes: [],
};
const store = createStore(
reducer,
initialState,
compose(applyMiddleware(
promiseMiddleware(),
thunkMiddleware)
)
);
Main magic
store.dispatch(loadNodes())
.then(() =>
ReactDOM.render(
<Provider store={store}>
<div>
<NodeListContainer />
<NodeContentContainer />
</div>
</Provider>,
document.getElementById('app')
)
);
Index.html
โ€ข Contains <div id="app"></div>
โ€ข Load react application
โ€ข React takes care of the rest
Result
On click
On another click
Useful links
โ€ข https://medium.com/@nesbtesh/react-best-practices-
a76fd0fbef21
โ€ข https://medium.com/lexical-labs-engineering/redux-best-
practices-64d59775802e
โ€ข https://egghead.io/courses/getting-started-with-redux
โ€ข https://www.gitbook.com/book/rajdee/redux-in-
russian/details
โ€ข https://medium.com/@dan_abramov/smart-and-dumb-
components-7ca2f9a7c7d0
Thank you!
Any questions?
Ask!

More Related Content

What's hot

React&redux
React&reduxReact&redux
React&reduxBlank Chen
ย 
Google App Engine Developer - Day4
Google App Engine Developer - Day4Google App Engine Developer - Day4
Google App Engine Developer - Day4Simon Su
ย 
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...Sencha
ย 
Getting Reactive with CycleJS and XStream
Getting Reactive with CycleJS and XStream Getting Reactive with CycleJS and XStream
Getting Reactive with CycleJS and XStream TechExeter
ย 
MySQL document_store
MySQL document_storeMySQL document_store
MySQL document_storeGiuseppe Maxia
ย 
Powershell For Developers
Powershell For DevelopersPowershell For Developers
Powershell For DevelopersIdo Flatow
ย 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrencypgriess
ย 
Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with WebpackThiago Temple
ย 
Concurrency Patterns with MongoDB
Concurrency Patterns with MongoDBConcurrency Patterns with MongoDB
Concurrency Patterns with MongoDBYann Cluchey
ย 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)Ashish Gupta
ย 
MuleSoft ESB Filtering data instead of Looping
MuleSoft ESB Filtering data instead of LoopingMuleSoft ESB Filtering data instead of Looping
MuleSoft ESB Filtering data instead of Loopingakashdprajapati
ย 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksVladimir Malyk
ย 
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package ExecutionPramod Singla
ย 
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark BrocatoSenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark BrocatoSencha
ย 
Igor Davydenko
Igor DavydenkoIgor Davydenko
Igor DavydenkoSCRUMguides
ย 
Couchbase - Introduction
Couchbase - IntroductionCouchbase - Introduction
Couchbase - IntroductionKnoldus Inc.
ย 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailCliffano Subagio
ย 
Automated YCSB Benchmarking
Automated YCSB BenchmarkingAutomated YCSB Benchmarking
Automated YCSB BenchmarkingMiro Cupak
ย 

What's hot (20)

React&redux
React&reduxReact&redux
React&redux
ย 
Google App Engine Developer - Day4
Google App Engine Developer - Day4Google App Engine Developer - Day4
Google App Engine Developer - Day4
ย 
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
ย 
Getting Reactive with CycleJS and XStream
Getting Reactive with CycleJS and XStream Getting Reactive with CycleJS and XStream
Getting Reactive with CycleJS and XStream
ย 
Lokijs
LokijsLokijs
Lokijs
ย 
MySQL document_store
MySQL document_storeMySQL document_store
MySQL document_store
ย 
Powershell For Developers
Powershell For DevelopersPowershell For Developers
Powershell For Developers
ย 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
ย 
Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
ย 
Concurrency Patterns with MongoDB
Concurrency Patterns with MongoDBConcurrency Patterns with MongoDB
Concurrency Patterns with MongoDB
ย 
Node js training (1)
Node js training (1)Node js training (1)
Node js training (1)
ย 
MuleSoft ESB Filtering data instead of Looping
MuleSoft ESB Filtering data instead of LoopingMuleSoft ESB Filtering data instead of Looping
MuleSoft ESB Filtering data instead of Looping
ย 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricks
ย 
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
ย 
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark BrocatoSenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
SenchaCon 2016: Ext JS + React: A Match Made in UX Heaven - Mark Brocato
ย 
Igor Davydenko
Igor DavydenkoIgor Davydenko
Igor Davydenko
ย 
Couchbase - Introduction
Couchbase - IntroductionCouchbase - Introduction
Couchbase - Introduction
ย 
Workshop React.js
Workshop React.jsWorkshop React.js
Workshop React.js
ย 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
ย 
Automated YCSB Benchmarking
Automated YCSB BenchmarkingAutomated YCSB Benchmarking
Automated YCSB Benchmarking
ย 

Similar to Headless drupal + react js Oleksandr Linyvyi

Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JSBinary Studio
ย 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
ย 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
ย 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
ย 
ReactJS for Beginners
ReactJS for BeginnersReactJS for Beginners
ReactJS for BeginnersOswald Campesato
ย 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdfDayNightGaMiNg
ย 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryjanet736113
ย 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
ย 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptxDayNightGaMiNg
ย 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for ProgrammersDavid Rodenas
ย 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
ย 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptxDivyanshGupta922023
ย 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React TogetherSebastian Pederiva
ย 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobXAnjali Chawla
ย 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Nativejoshcjensen
ย 
Nodejs Session01
Nodejs Session01Nodejs Session01
Nodejs Session01Jainul Musani
ย 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift FrameworkXebia IT Architects
ย 

Similar to Headless drupal + react js Oleksandr Linyvyi (20)

React js
React jsReact js
React js
ย 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JS
ย 
React js
React jsReact js
React js
ย 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
ย 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
ย 
ReactJS.ppt
ReactJS.pptReactJS.ppt
ReactJS.ppt
ย 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
ย 
ReactJS for Beginners
ReactJS for BeginnersReactJS for Beginners
ReactJS for Beginners
ย 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdf
ย 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
ย 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
ย 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
ย 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
ย 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
ย 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
ย 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React Together
ย 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
ย 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
ย 
Nodejs Session01
Nodejs Session01Nodejs Session01
Nodejs Session01
ย 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
ย 

More from DrupalCamp Kyiv

Speed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout BuilderSpeed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout BuilderDrupalCamp Kyiv
ย 
Performance Monitoring with Google Lighthouse
Performance Monitoring with Google LighthousePerformance Monitoring with Google Lighthouse
Performance Monitoring with Google LighthouseDrupalCamp Kyiv
ย 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...DrupalCamp Kyiv
ย 
Acquia BLT for the Win, or How to speed up the project setup, development an...
Acquia BLT for the Win, or  How to speed up the project setup, development an...Acquia BLT for the Win, or  How to speed up the project setup, development an...
Acquia BLT for the Win, or How to speed up the project setup, development an...DrupalCamp Kyiv
ย 
Upgrading to Drupal 9
Upgrading to Drupal 9Upgrading to Drupal 9
Upgrading to Drupal 9DrupalCamp Kyiv
ย 
THE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REALTHE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REALDrupalCamp Kyiv
ย 
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDFRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDDrupalCamp Kyiv
ย 
DRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCHDRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCHDrupalCamp Kyiv
ย 
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...DrupalCamp Kyiv
ย 
Blackfire Workshop
Blackfire WorkshopBlackfire Workshop
Blackfire WorkshopDrupalCamp Kyiv
ย 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDrupalCamp Kyiv
ย 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESDrupalCamp Kyiv
ย 
1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TODrupalCamp Kyiv
ย 
UX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATIONUX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATIONDrupalCamp Kyiv
ย 
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?DrupalCamp Kyiv
ย 
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERATECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERADrupalCamp Kyiv
ย 
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPALPROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPALDrupalCamp Kyiv
ย 
DRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTRDRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTRDrupalCamp Kyiv
ย 
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...DrupalCamp Kyiv
ย 
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONSSEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONSDrupalCamp Kyiv
ย 

More from DrupalCamp Kyiv (20)

Speed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout BuilderSpeed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout Builder
ย 
Performance Monitoring with Google Lighthouse
Performance Monitoring with Google LighthousePerformance Monitoring with Google Lighthouse
Performance Monitoring with Google Lighthouse
ย 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
ย 
Acquia BLT for the Win, or How to speed up the project setup, development an...
Acquia BLT for the Win, or  How to speed up the project setup, development an...Acquia BLT for the Win, or  How to speed up the project setup, development an...
Acquia BLT for the Win, or How to speed up the project setup, development an...
ย 
Upgrading to Drupal 9
Upgrading to Drupal 9Upgrading to Drupal 9
Upgrading to Drupal 9
ย 
THE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REALTHE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REAL
ย 
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDFRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
ย 
DRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCHDRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCH
ย 
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
ย 
Blackfire Workshop
Blackfire WorkshopBlackfire Workshop
Blackfire Workshop
ย 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
ย 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ย 
1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO
ย 
UX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATIONUX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATION
ย 
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
ย 
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERATECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
ย 
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPALPROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
ย 
DRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTRDRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTR
ย 
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
ย 
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONSSEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
ย 

Recently uploaded

WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
ย 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
ย 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
ย 
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort ServiceEnjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort ServiceDelhi Call girls
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
ย 
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRLLucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRLimonikaupta
ย 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...roncy bisnoi
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
ย 
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
ย 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubaikojalkojal131
ย 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
ย 
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445ruhi
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
ย 
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...Delhi Call girls
ย 

Recently uploaded (20)

WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
ย 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
ย 
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐ŸฅตLow Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
ย 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
ย 
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort ServiceEnjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
Enjoy NightโšกCall Girls Dlf City Phase 3 Gurgaon >เผ’8448380779 Escort Service
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
ย 
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRLLucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
ย 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
ย 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
ย 
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
ย 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
ย 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
ย 
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
ย 
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
ย 

Headless drupal + react js Oleksandr Linyvyi

  • 1. Headless Drupal + ReactJS Oleksandr Linyvyi Drupal Developer, Adyax oleksandr.linyvyi@gmail.com
  • 2.
  • 4. Drupal is used only for few things โ€ข Data storage (Drupal DB basically) โ€ข Data provider (Services) โ€ข Serve single HTML page with React app
  • 5. Frontend part is the responsibility of React app only
  • 7. React is used for โ€ข Data fetching โ€ข Data display Basically it does all the UI stuff
  • 8. React specific things โ€ข Virtual DOM โ€ข JSX โ€ข Consequence - markup is mixed with JS โ€ข And it is hard to get used to it ๏Š โ€ข Also โ€“ a lot of 3rd party libs may (and should be) used
  • 9. <Button color=โ€œgreen" borderSize={2}> Click Me </Button> React.createElement( Button, {color: 'green', borderSize: 2}, 'Click Meโ€˜ ) prevraschaetsโ€™a v
  • 10. Babel http://babeljs.io/ Babel is a JavaScript compiler.
  • 11. function Item(props) { return <li>{props.message}</li>; } function TodoList() { const todos = [ 'finish doc', 'submit pr', 'nag dan to reviewโ€˜ ]; return ( <ul> {todos.map((message) => <Item key={message} message={message} /> )} </ul> ); }
  • 12. Smart / dumb components โ€ข Dumb (presentational) โ€“ are concerned with how things look โ€ข Smart (container) โ€“ are concerned with how things work
  • 13. Redux โ€ข Keeps application state in single place โ€ข State is read only โ€ข State transitions are predictable and consistent โ€ข Changes in state are made only by dispatching an action โ€ข And reducers describe how state is transformed by actions
  • 14. State { selectedNode: 1, nodes: [ { nid: 1, title: 'Consider using Redux', body: 'Lorem ipsum' }, { nid: 2, title: 'Keep all state in a single tree', body: 'Dolor sit amet' } ] }
  • 16. Reducers function selectedNode(state = null, action) { switch (action.type) { case 'SELECT_NODE': return action.nid default: return state } }
  • 18. New state { selectedNode: 2, // changed nodes: [ { nid: 1, title: 'Consider using Redux', body: 'Lorem ipsum' }, { nid: 2, title: 'Keep all state in a single tree', body: 'Dolor sit amet' } ] }
  • 19. Package management Where to search for packages? โ€ข Npmjs.com โ€ข Github.com NPM is your tool: $ npm install react react-dom --save
  • 20. Some useful packages โ€ข react, react-dom โ€ข react-redux โ€ข redux-thunk โ€ข immutable โ€ข reselect โ€ข lodash
  • 21. Demo app โ€ข Load a list of nodes โ€ข Display a list of clickable node titles โ€ข Display node body on click on node title
  • 24.
  • 25. React part Used packages โ€ข React โ€ข React-dom โ€ข React-redux โ€ข Redux-thunk โ€ข Lodash
  • 26. State { selectedNode: 1, nodes: [ { nid: 1, title: 'Consider using Redux', body: 'Lorem ipsum' }, { nid: 2, title: 'Keep all state in a single tree', body: 'Dolor sit amet' } ] }
  • 28. Reducers function selectedNode(state = null, action) { switch (action.type) { case 'SELECT_NODE': return action.nid; default: return state; } } function nodes(state = [], action) { switch (action.type) { case 'STORE_NODES': return action.nodes; default: return state; } }
  • 29. Async action export function loadNodes() { return (dispatch) => { return fetch('http://d8react.local/rest/nodes', { credentials: 'include', }) .then((response) => { return response.json(); }) .then((json) => { dispatch({ type: 'STORE_NODES', nodes: json }); }) .catch((error) => console.log(error.message)) } }
  • 30. import { connect } from 'react-redux'; import NodeList from 'NodeList'; const mapStateToProps = (state) => { return { nodes: state.nodes } }; const mapDispatchToProps = (dispatch) => { return { onClick: (nid) => dispatch({ type: 'SELECT_NODE', nid }) }; }; export default connect( mapStateToProps, mapDispatchToProps) (NodeList); Node list (smart)
  • 31. Node list (dumb) import React from 'react'; export default (props) => ( <ul> {props.nodes.map((node) => { return <li key={node.nid[0].value} onClick={() => props.onClick(node.nid[0].value)} > {node.title[0].value} </li>; })} </ul> );
  • 32. Node content (smart) import { connect } from 'react-redux'; import _ from 'lodash'; import NodeContent from 'NodeContent'; const mapStateToProps = (state) => { return { node: _.find(state.nodes, (node) => node.nid[0].value == state.selectedNode ) } }; export default connect(mapStateToProps)(NodeContent);
  • 33. Node content (dumb) import React from 'react'; export default (props) => { return !!props.node ? <div>{props.node.body[0].value}</div> : null; };
  • 34. All together import React from 'react'; import ReactDOM from 'react-dom'; import { createStore, applyMiddleware, compose } from 'redux'; import thunkMiddleware from 'redux-thunk'; import promiseMiddleware from 'redux-promise-middleware'; import { Provider } from 'react-redux'; import reducer from './reducers'; import { loadNodes } from './actions'; import NodeListContainer from './NodeListContainer'; import NodeContentContainer from './NodeContentContainer';
  • 35. All together const initialState = { selectedNode: null, nodes: [], }; const store = createStore( reducer, initialState, compose(applyMiddleware( promiseMiddleware(), thunkMiddleware) ) );
  • 36. Main magic store.dispatch(loadNodes()) .then(() => ReactDOM.render( <Provider store={store}> <div> <NodeListContainer /> <NodeContentContainer /> </div> </Provider>, document.getElementById('app') ) );
  • 37. Index.html โ€ข Contains <div id="app"></div> โ€ข Load react application โ€ข React takes care of the rest
  • 41. Useful links โ€ข https://medium.com/@nesbtesh/react-best-practices- a76fd0fbef21 โ€ข https://medium.com/lexical-labs-engineering/redux-best- practices-64d59775802e โ€ข https://egghead.io/courses/getting-started-with-redux โ€ข https://www.gitbook.com/book/rajdee/redux-in- russian/details โ€ข https://medium.com/@dan_abramov/smart-and-dumb- components-7ca2f9a7c7d0

Editor's Notes

  1. ะ’ัั–ะผ ะฟั€ะธะฒั–ั‚ะฐะฝะฝั. ะŸั€ะตะดัั‚ะฐะฒะปะตะฝะฝั ัะตะฑะต. ะŸั€ะตะดัั‚ะฐะฒะปะตะฝะฝั ั‚ะตะผะธ, ะฟั€ะพ ั‰ะพ ะฟั–ะดะต ะผะพะฒะฐ.
  2. ะ”ั€ัƒะฟะฐะป ั– ั€ะตะฐะบั‚ (ะฝะฐะฒั–ั‚ัŒ ะบะพะปัŒะพั€ะธ ะปะพะณะพ ัั…ะพะถั–, ะปั–ะป). ะฏะบะธะผ ั‡ะธะฝะพะผ ะฑัƒะปะพ ะฒะธั€ั–ัˆะตะฝะพ ะฒะธะบะพั€ะธัั‚ะฐั‚ะธ ั†ัŽ ะทะฒโ€ัะทะบัƒ? ะŸะตั€ะตะดั–ัั‚ะพั€ั–ั.
  3. ะัƒ, ะผะธ ะถ ะฒัะต ั‚ะฐะบะธ ะดั€ัƒะฟะฐะป ะบะพะผะฟะฐะฝั–ั ั‡ะธ ะฝั–? ๏Š
  4. ะ’ั–ะดะผั–ั‚ะธั‚ะธ ั‚ะต, ั‰ะพ ั‚ัƒั‚ ะฝะต ั„ั–ะณัƒั€ัƒั” ั„ั€ะพะฝั‚ะตะฝะด ั‡ะฐัั‚ะธะฝะฐ โ€“ ั†ะธะผ ะทะฐะนะผะฐั”ั‚ัŒัั ั€ะตะฐะบั‚ ะฐะฟะฟ. ะะฐัั‚ัƒะฟะฝะธะน ัะปะฐะนะด.
  5. ะัƒ, ะฐ ั‚ะพะผัƒ, ัˆะพ ะดะฐะฒะฐะนั‚ะต ะฟะพะฟั€ะพะฑัƒั”ะผ? ะ’ะฐะน ะฝะพั‚?
  6. ะ’ะฟั€ะธะฝั†ะธะฟั–, ั”ะดะธะฝะต ั‡ะธะผ ั€ะตะฐะบั‚ ะทะฐะนะผะฐั”ั‚ัŒัั โ€“ ั†ะต UI.
  7. ะ’ะฟั€ะธะฝั†ะธะฟั–, ั”ะดะธะฝะต ั‡ะธะผ ั€ะตะฐะบั‚ ะทะฐะนะผะฐั”ั‚ัŒัั โ€“ ั†ะต UI.