Guest User

Untitled

a guest
Jan 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /*
  2. 1. break the UI into a component hierarchy
  3. 2. build a static version in React
  4. 3. identify the minimal (but complete) representation of UI state
  5. 4. Identify where your state should live
  6. 5. Add inverse data flow
  7.  
  8. 3. identify the minimal (but complete) representation of UI state
  9.  
  10.  
  11. 4. identify where your state should live
  12. identifying which components own , ot mutates, the app's state
  13.  
  14. for each piece of state in your application:
  15. 1) identify every component that renders something based on that state
  16. 2) find a common owner component (a single component above all the components
  17. that need that state in the hierarchy)
  18. 3) Either the common owner or another component higher up the in hierarchy should
  19. own the state
  20.  
  21. 5. Add inverse data flow
  22. update the top level state-owner by passing funcs as props to its child components, and
  23. appraise the child components of their values by passing in the top level state as a prop
  24.  
  25.  
  26. the TodoList example, the component hierarchy would begin with:
  27.  
  28. * TodoApp
  29. * Title
  30. * ToDoList
  31. * InputForm
  32. */
  33.  
  34. const data = ["item one", "item two", "item three"]
  35.  
  36. class TodoApp extends React.Component {
  37. constructor(props) {
  38. super(props)
  39. this.state = { items: data }
  40. }
  41.  
  42. render() {
  43. return(
  44. <div>
  45. <h3>TODO</h3>
  46. <TodoList items={this.state.items} />
  47. <form>
  48. <input />
  49. <button >Enter item #{this.state.items.length + 1} </button>
  50. </form>
  51. </div>
  52. )
  53. }
  54. }
  55.  
  56. class TodoList extends React.Component {
  57. render() {
  58.  
  59. return(
  60. <ul>
  61. {
  62. this.props.items.map((item) => (
  63. <li>{item}</li>
  64. ))
  65. }
  66. </ul>
  67. )
  68. }
  69. }
Add Comment
Please, Sign In to add comment