Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to React.js

Max Stoiber
December 06, 2016

Introduction to React.js

The slides for my introduction to React.js talk!

Max Stoiber

December 06, 2016
Tweet

More Decks by Max Stoiber

Other Decks in Technology

Transcript

  1. React.createElement('h1', { className: 'heading' }, 'Hello World') // will render

    this w/ ReactDOM <h1 class="heading">Hello World</h1>
  2. React.createElement('div', null, React.createElement('h1', { className: 'heading' }, 'Hello World') )

    // will render this w/ ReactDOM <div> <h1 class="heading">Hello World</h1> </div>
  3. React.createElement('div', { className: 'wrapper' }, React.createElement('h1', { className: 'heading' },

    'Hello World') ) // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>
  4. const Wrapper = function (props) { return React.createElement('div', { className:

    'wrapper' }) } React.createElement(Wrapper, null, React.createElement('h1', { className: 'heading' }, 'Hello World') ) // will render this w/ ReactDOM <div class="wrapper"> </div>
  5. const Wrapper = function (props) { return React.createElement('div', { className:

    'wrapper' }, props.children) } React.createElement(Wrapper, null, React.createElement('h1', { className: 'heading' }, 'Hello World') ) // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div> Component!
  6. React.createElement('h1', { className: 'heading' }, 'Hello World') // will return

    something like { type: 'h1', props: { className: 'heading' }, children: ['Hello World'] }
  7. React.createElement(Wrapper, null, React.createElement('h1', { className: 'heading' }, 'Hello World') )

    // will return something like { type: Wrapper, props: null, children: [{ type: 'h1', props: { className: 'heading' }, children: ['Hello World'] }] }
  8. // After { type: 'h1', props: { className: 'heading' },

    children: ['This is new'] } // Before { type: 'h1', props: { className: 'heading' }, children: ['Hello World'] }
  9. // After { type: 'h1', props: { className: 'heading' },

    children: ['This is new'] } // Before { type: 'h1', props: { className: 'heading' }, children: ['Hello World'] } // What changed?
  10. // After { type: 'h1', props: { className: 'heading' },

    children: ['This is new'] } // Before { type: 'h1', props: { className: 'heading' }, children: ['Hello World'] } // What changed?
  11. JSX

  12. const Wrapper = function (props) { return React.createElement('div', { className:

    'wrapper' }, props.children) } React.createElement(Wrapper, null, React.createElement('h1', { className: 'heading' }, 'Hello World') ) // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>
  13. const Wrapper = function (props) { return React.createElement('div', { className:

    'wrapper' }, props.children) } React.createElement(Wrapper, null, <h1 className="heading">Hello World</h1> ) // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>
  14. const Wrapper = function (props) { return <div className="wrapper">{ props.children

    }</div> } React.createElement(Wrapper, null, <h1 className="heading">Hello World</h1> ) // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>
  15. const Wrapper = function (props) { return <div className="wrapper">{ props.children

    }</div> } <Wrapper> <h1 className="heading">Hello World</h1> </Wrapper> // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>
  16. const Wrapper = function (props) { return React.createElement('div', { className:

    'wrapper' }) } React.createElement(Wrapper, null, React.createElement('h1', { className: 'heading' }, 'Hello World') ) // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>
  17. const Wrapper = function (props) { return <div className="wrapper">{ props.children

    }</div> } <Wrapper> <h1 className="heading">Hello World</h1> </Wrapper> // will render this w/ ReactDOM <div class="wrapper"> <h1 class="heading">Hello World</h1> </div>