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

React.js for WordPress Developers

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

React.js for WordPress Developers

Avatar for Nikolay Bachiyski

Nikolay Bachiyski

April 16, 2016
Tweet

More Decks by Nikolay Bachiyski

Other Decks in Programming

Transcript

  1. N I KO L AY B A C H I

    Y S K I , A U TO M AT T I C , W O R D C A M P H E L S I N K I , A P R I L 1 6 , 2 0 1 6
  2. A U TO M AT T I C E X

    T R A P O L AT E . M E
  3. A U TO M AT T I C E X

    T R A P O L AT E . M E @ N I KO L AY B
  4. R E S T A P I ↓ S I

    N G L E - PA G E A P P S
  5. C H A N G E L E T '

    S TA L K A B O U T
  6. C L A S S I C V S .

    S I N G L E - PA G E A P P S
  7. C H A N G E 㱺 R E F

    R E S H C L A S S I C
  8. C H A N G E 㱺 S I N

    G L E - PA G E
  9. C H A N G E 㱺 S I N

    G L E - PA G E
  10. const Post = React.createClass( { render() { return ( <div

    className="post"> <p className="content"> { this.props.post.content } </p> <PostMeta post={ this.props.post } /> </div> ); } } );
  11. const Post = React.createClass( { render() { return ( <div

    className="post"> <p className="content"> { this.props.post.content } </p> <PostMeta post={ this.props.post } /> </div> ); } } );
  12. const Post = React.createClass( { render() { return ( <div

    className="post"> <p className="content"> { this.props.post.content } </p> <PostMeta post={ this.props.post } /> </div> ); } } ); J SX
  13. const Post = React.createClass( { function render() { return (

    React.DOM.div( {className: 'post'}, [ React.DOM.p( null, this.props.post.content ), PostMeta( {post: this.props.post} ) ); ); } } );
  14. const Post = React.createClass( { render() { return ( <div

    className="post"> <p className="content"> { this.props.post.content } </p> <PostMeta post={ this.props.post } /> </div> ); } } );
  15. const Post = React.createClass( { render() { return ( <div

    className="post"> <p className="content"> { this.props.post.content } </p> <PostMeta post={ this.props.post } /> </div> ); } } );
  16. const PostMeta = React.createClass( { getInitialState() { return { hidden:

    true }; }, onToggle() { this.setState( { hidden: ! this.state.hidden } ); }, render() { return ( <div className="meta"> { this.props.post.author } <button onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); } } );
  17. const PostMeta = React.createClass( { getInitialState() { return { hidden:

    true }; }, onToggle() { this.setState( { hidden: ! this.state.hidden } ); }, render() { return ( <div className="meta"> { this.props.post.author } <button onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); } } );
  18. const PostMeta = React.createClass( { getInitialState() { return { hidden:

    true }; }, onToggle() { this.setState( { hidden: ! this.state.hidden } ); }, render() { return ( <div className="meta"> { this.props.post.author } <button onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); } } );
  19. const PostMeta = React.createClass( { getInitialState() { return { hidden:

    true }; }, onToggle() { this.setState( { hidden: ! this.state.hidden } ); }, render() { return ( <div className="meta"> { this.props.post.author } <button onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); } } );
  20. const PostMeta = React.createClass( { getInitialState() { return { hidden:

    true }; }, onToggle() { this.setState( { hidden: ! this.state.hidden } ); }, render() { return ( <div className="meta"> { this.props.post.author } <button onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); } } ); R E - R E N D E RS
  21. C O M P O N E N T S

    L E T ' S TA L K A B I T M O R E A B O U T
  22. <MasterBar> <UserGreeting user="…"> <Avatar login={ this.props.user.login } /> Howdy, {

    this.props.user.nickname } <LogOutLink id={ this.props.user.id } /> </UserGreeting> </MasterBar>
  23. B U I L D I N G B LO

    C KS O F O U R A P P L I C AT I O N
  24. K E E P LO G I C A N

    D M A R K U P … A P O P U L A R B E S T P R A C T I C E S A Y S …
  25. S E PA R AT I O N O F

    C O N C E R N S I S G O O D, R I G H T ?
  26. W H E N D O W E N E

    E D A N E V E N T H A N D L E R W I T H O U T T H E D O M E L E M E N T I T I S B O U N D TO ?
  27. W H E N D O W E N E

    E D A N E V E N T H A N D L E R W I T H O U T T H E D O M E L E M E N T I T I S B O U N D TO ? onClick() <button>
  28. W H E N D O W E N E

    E D A D O M E L E M E N T W I T H O U T T H E E V E N T H A N D L E R S F O R I T S A C T I O N S ? onClick() <button>
  29. 0 . R U N r e n d e

    r ( ) O N E V E RY U P D A T E
  30. 1 . D I F F W I T H

    P R E V I O U S T R E E O N E V E RY U P D A T E
  31. 2 . CO M P U T E M I

    N I M U M S E T O F D O M C H A N G E S O N E V E RY U P D A T E
  32. 3 . B ATC H - E X E C

    U T E A L L D O M U P D AT E S O N E V E RY U P D A T E
  33. V I R T U A L D O M

    : N OT O N LY S P E E D!
  34. S E R V E R-S I D E R

    E N D E R I N G
  35. R U N N I N G I N A

    W E B W O R K E R
  36. render() { return ( <div className="meta"> { this.props.post.author } <button

    onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); }
  37. render() { return ( <div className="meta"> { this.props.post.author } <button

    onClick={ this.onToggle }> { this.state.hidden ? 'More' : 'Hide' } </button> ( this.state.hidden ? <p>…extra meta…</p> : null ) </div> ); }
  38. RO U T E R + S TAT E http://redux.js.org

    https://github.com/reactjs/react-router https://egghead.io
  39. C O M P O N E N T S

    , N OT T E M P L AT E S
  40. R E - R E N D E R ,

    D O N ' T TO U C H T H E D O M
  41. V I R T U A L D O M

    I S S I M P L E , FA S T, F U N L E T ' S TA L K A B O U T
  42. Q U E S T I O N S ?

    @ N I KO L AY B