getting started with reactjs

24
GETTING STARTED WITH REACTJS VIEW

Upload: sandeep-kumar-patel

Post on 14-Jan-2017

746 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Getting Started With ReactJS

GETTING STARTED

WITH REACTJS

VIEW

Page 2: Getting Started With ReactJS

AGENDAInstalling ReactJS ReactJS event

handlingReactJS lifecycle example

Configuring ReactJS Useful non-DOM attributes

Stateful custom component

Using ReactJS ReactJS component lifecycle

Precompiled JSX for production

What is JSX ReactJS initialization phase

JSX file watcher

Custom components with JSX

ReactJS lifetime phase

Developing a digital clock using ReactJS

ReactJS inline style ReactJS teardown phase

Debugging ReactJS

Page 3: Getting Started With ReactJS

OUT OF SCOPEComparing ReactJS with Other frameworkBuilding React RoutingIsomorphic ReactReact NativeSynthetic EventReact ES6 implementation

Page 4: Getting Started With ReactJS

WHO AM I? Sandeep Kumar Patel Intuit PTG Developer Blog: www.tutorialsavvy.com

Page 5: Getting Started With ReactJS

REQUIRED SOFTWARECode Editor (WebStorm)

NPM (Node Package Manager)GIT (Code Repository)

Page 6: Getting Started With ReactJS

REACTJS INSTALLATIONCreate a project DirectoryChange the Current Working DirectoryRun npm init for creating package.jsonRun npm install react --save Verify node_modules directory

Page 7: Getting Started With ReactJS

CONFIGURING REACTJSLOCAL<script src="node_modules/react/react.js"></script><script src="node_modules/react/JSXTransformer.js"> </script>CDN<script src="https://fb.me/react-0.13.3.min.js"></script><script src="https://fb.me/JSXTransformer-0.13.3.js"></script>

Page 8: Getting Started With ReactJS

WHAT IS JSX ?JavaScript syntax extensionHTML like syntaxJSX TransformerIn browser compilation

Page 9: Getting Started With ReactJS

CUSTOM COMPONENTS WITH JSX <script type="text/jsx"> var HelloMessage = React.createClass({ render: function() { return ( <h1 className="headerStyle"> Hello ReactJS </h1> ); } }); React.render(<HelloMessage/>, document.body); </script>

Page 10: Getting Started With ReactJS

REACTJS INLINE STYLEKey-value pairvar styleObject={ styleAttribute: "styleValue", };styleAttribute : camel casestyleValue: wrapped in double quotesExample

Page 11: Getting Started With ReactJS

REACTJS EVENT HANDLINGSimilar to HTML DOM eventsDifference in naming handlersHandlers are camel caseonclick becomes onClickExample

Page 12: Getting Started With ReactJS

USEFUL NON-DOM ATTRIBUTESkey: This is an optional attribute can be used for uniquely identify each component in the page.ref: This is an optional attribute that can be used to access the child element from outside of render() method.dangerouslySetInnerHTML: This attribute can be used inside JSX element to set HTML content inside the component.Example

Page 13: Getting Started With ReactJS

REACTJS COMPONENT LIFECYCLE

Page 14: Getting Started With ReactJS

REACTJS INITIALIZATION PHASEelement is created for the 1st time.

has slight changes during lifetime

Page 15: Getting Started With ReactJS

REACTJS LIFETIME PHASEthe phase when element lives.changes its states and properties

Page 16: Getting Started With ReactJS

REACTJS TEARDOWN PHASEthe phase when element finishes its executionclean-up takes place.

Page 17: Getting Started With ReactJS

REACTJS LIFECYCLE EXAMPLELet’s checkout an simple React Component <Welcome>To determine the order of execution of these lifecycle methodsExample

Page 18: Getting Started With ReactJS

STATEFUL CUSTOM COMPONENTTo refer the component state : this.statesTo change the component state : this.setState(<object>) Object: {key:value}Example

Page 19: Getting Started With ReactJS

PRECOMPILED JSX FOR PRODUCTIONRemove in browser JSX transformerReact-toolsnpm install -g react-toolsExample

Page 20: Getting Started With ReactJS

JSX FILE WATCHERComes with react-toolsjsx --watch dev production

Page 21: Getting Started With ReactJS

DEVELOPING A DIGITAL CLOCK USING REACTJSDevelop a digital Clock in React Component to Hour minute and seconds

Page 22: Getting Started With ReactJS

DEBUGGING REACTJSReact Chrome Debugging toolhttps://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi

Page 23: Getting Started With ReactJS

ADD VIRTUAL DOMVirtual DOM is Simple and Fast

Batch Execution updates