├── cover.jpg ├── life_cycle ├── react-delete-tree.png ├── birth │ ├── react-element-tree.png │ ├── managing_children_components_and_mounting.md │ ├── premounting_with_componentwillmount.md │ ├── component_render.md │ ├── post_mount_with_component_did_mount.md │ └── initialization_and_construction.md ├── update │ ├── react-tree-update.png │ ├── rerendering_and_children_updates.md │ ├── tapping_into_componentwillupdate.md │ ├── postrender_with_componentdidupdate.md │ ├── component_will_receive_props.md │ └── using_should_component_update.md ├── react-lifecycle-flow-chart-states.png ├── the_life_cycle_recap.md ├── death_unmounting_indepth.md ├── lifecycle_methods_overview.md ├── introduction.md ├── birth_mounting_indepth.md └── growth_update_indepth.md ├── assets └── src │ └── React Element Tree.sketch ├── patterns ├── react-indepth-avatar-list.png ├── react-indepth-details-list.png ├── component_evolution_and_composition.md ├── the_evolution_of_a_list_component.md ├── higher_order_components.md └── rendering_different_content.md ├── .gitignore ├── LICENSE ├── react_basics └── introduction.md ├── about_the_authors.md ├── SUMMARY.md └── README.md /cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/cover.jpg -------------------------------------------------------------------------------- /life_cycle/react-delete-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/life_cycle/react-delete-tree.png -------------------------------------------------------------------------------- /assets/src/React Element Tree.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/assets/src/React Element Tree.sketch -------------------------------------------------------------------------------- /life_cycle/birth/react-element-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/life_cycle/birth/react-element-tree.png -------------------------------------------------------------------------------- /life_cycle/update/react-tree-update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/life_cycle/update/react-tree-update.png -------------------------------------------------------------------------------- /patterns/react-indepth-avatar-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/patterns/react-indepth-avatar-list.png -------------------------------------------------------------------------------- /patterns/react-indepth-details-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/patterns/react-indepth-details-list.png -------------------------------------------------------------------------------- /life_cycle/react-lifecycle-flow-chart-states.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevelopmentArc/react-indepth/HEAD/life_cycle/react-lifecycle-flow-chart-states.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node rules: 2 | ## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 3 | .grunt 4 | 5 | ## Dependency directory 6 | ## Commenting this out is preferred by some people, see 7 | ## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git 8 | node_modules 9 | 10 | # Book build output 11 | _book 12 | 13 | # eBook build output 14 | *.epub 15 | *.mobi 16 | *.pdf 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 DevelopmentArc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /react_basics/introduction.md: -------------------------------------------------------------------------------- 1 | # [WIP] React From The Inside Out 2 | 3 | ***This section is currently being researched*** 4 | 5 | In the meantime, there are ton of getting started resources already available. If you are new to React we recommend spending some time looking at these fantastic resources: 6 | 7 | * [React Official Site](http://facebook.github.io/react/) 8 | * [Awesome React](https://github.com/enaqx/awesome-react) - A comprehensive list of resources 9 | * [Learning React, Getting Started](https://scotch.io/tutorials/learning-react-getting-started-and-concepts) - Basic intro article 10 | 11 | From a book development perspective, our first focus will be on the [Life Cycle chapters](../life_cycle/introduction.md) and we will circle back to this section soon. 12 | 13 | ## Guiding Principals to learning React 14 | Unlike most intro books, we want to have different goals for our Basics Section. We will dig into the underpinnings of React and look at how to create applications from the bottom up. We feel that understanding the internals of a UI system helps drive development choices. We plan to explore React from this guiding principal. 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /about_the_authors.md: -------------------------------------------------------------------------------- 1 | # About the Authors 2 | 3 | ### James Polanco 4 | [@jamespolanco](https://twitter.com/jamespolanco) 5 | 6 | In his role as co-founder and CTO of DevelopmentArc®, James strives to take powerful business ideas and integrate them into elegant technological experiences to help clients achieve their overall strategic goals. Since 1996, James has helped plan, guide and create interactive and web-based solutions for companies including Adobe, Toyota Motor Sports, BlueKai, VMWare, Macromedia, and DHAP Digital. James is also an international speaker, presenting on technology implementations & processes and a published author on the topic of full team product development and company workflows. 7 | 8 | 9 | ### Aaron Pedersen 10 | [@aaronpedersen](https://twitter.com/aaronpedersen) 11 | 12 | As co-founder and CEO of DevelopmentArc®, a boutique development firm and parent company of Pedanco, Aaron Pedersen’s passion lies in helping businesses streamline process making teams work more effectively through innovative technology solutions. A published author, expert speaker, and sought-after business consultant and trainer, Aaron works with a wide range of companies, from Fortune 500 corporations and multi-chain hospitality companies to emerging brands and seed-round startups including Toyota Motor Sports, DHAP Digital, Adobe, KitchenNetwork and FitStar. -------------------------------------------------------------------------------- /life_cycle/update/rerendering_and_children_updates.md: -------------------------------------------------------------------------------- 1 | # Re-rendering and Children Updates 2 | Once again we return to `render()`. Now that our `props` and `state` are all updated[^1] we can apply them to our content and children. Just like the initial render,[ all the same rules and conditions apply](../birth/component_render.md). 3 | 4 | Unlike our first render, React performs different management when it comes to the generated Elements. The main difference is around the initialization phase and children Elements of the Component. 5 | 6 |  7 | 8 | React compares the current Element tree structure returned from the `render()` method. React uses the generated keys (or assigned keys) to match each Element to a Component instance. React determines if we have new instances (**A.3**), removing instances (**A.0.1**) or are updating existing instances (**A**, **A.0**, **A.0.0**). 9 | 10 | If the keys are the same, then React will pass the `props` to the existing instance, kicking off its Update life cycle. If we have added new Components or changed keys, React will create new instances from the Element data. These new Components then enter the Birth/Mounting phase. 11 | 12 | ***Up Next:*** [Post-Render with `componentDidUpdate()`](postrender_with_componentdidupdate.md) 13 | 14 | --- 15 | 16 | [^1] As mentioned earlier, the asynchronicity nature of state is now fully applied and can be accessed safely. 17 | 18 | 19 | -------------------------------------------------------------------------------- /life_cycle/birth/managing_children_components_and_mounting.md: -------------------------------------------------------------------------------- 1 | # Managing Children Components and Mounting 2 | Now that we have completed the first render pass, our `render()` method returns a single React Element. This Element may have children elements. Those children may also have children, and so on. 3 | 4 |  5 | 6 | With the potential for an *n* depth tree of Elements, each of the Elements need to go through their own entire life cycle process. Just like the parent Element, React creates a new instance for each child. They go through construction, default props, initial state, `componentWillMount()` and `render()`. If the child has children, the process starts again...all the way down. 7 | 8 | One of the most powerful concepts in React is the ability to easily compose complex layout through nesting of children. It is encouraged to keep your Components as *'dumb'* as possible. The idea is to only have container[^1] components managing higher level functionality. 9 | 10 | Because this is the preferred way of development, this means we will have a lot of smaller components that also have their own life cycle. Keep this in mind as we continue through the life cycle, because every Component will follow the same pattern. 11 | 12 | ***Up Next:*** [Post-Mount with `componentDidMount()`](post_mount_with_component_did_mount.md) 13 | 14 | --- 15 | 16 | [^1] See [Presentational and Container Components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.pnmirdrso) by Dan Abramov for more details 17 | -------------------------------------------------------------------------------- /life_cycle/the_life_cycle_recap.md: -------------------------------------------------------------------------------- 1 | # The Life Cycle Recap 2 | We have now worked through the three phases of the React life cycle: [Birth/Mounting](birth_mounting_indepth.md), [Growth/Update](growth_update_indepth.md) and finally [Death/Unmount](death_unmounting_indepth.md). By having these phases and corresponding methods React provides us a clear path for developing Components. These phases also allow us to begin to optimize our Components and our entire application. 3 | 4 | To review, the methods and order called are: 5 | 6 | ## Birth / Mounting 7 | 1. Initialize / Construction 8 | 2. `getDefaultProps()` *(React.createClass)* or `MyComponent.defaultProps` *(ES6 class)* 9 | 3. `getInitialState()` *(React.createClass)* or `this.state = ...` *(ES6 constructor)* 10 | 4. `componentWillMount()` 11 | 5. `render()` 12 | 6. Children initialization & life cycle kickoff 13 | 7. `componentDidMount()` 14 | 15 | ## Growth / Update 16 | 1. `componentWillReceiveProps()` 17 | 2. `shouldComponentUpdate()` 18 | 3. `componentWillUpdate()` 19 | 3. `render()` 20 | 4. Children Life cycle methods 21 | 5. `componentDidUpdate()` 22 | 23 | ## Death / Un-Mounting 24 | 1. `componentWillUnmount()` 25 | 4. Children Life cycle methods 26 | 5. Instance destroyed for Garbage Collection 27 | 28 | ## Life Cycle Flowchart and `setState()` safety 29 | 30 | In addition, this flow chart by [Peter Beshai](https://twitter.com/pbesh) breaks down the different methods and also calls out when `this.setState()` is safe and NOT safe to call: 31 | 32 |  -------------------------------------------------------------------------------- /life_cycle/death_unmounting_indepth.md: -------------------------------------------------------------------------------- 1 | # Death/Unmount In-depth 2 | After our Component has spent time in the Update phase, we eventually enter the Death phase. During this phase our component is Unmounted from the Native UI stack and is marked for Garbage Collection. 3 | 4 | We enter this phase when our UI changes and the Element Tree no longer has a matching key to our Component. This could be changing layout or programmatically changing keys (forcing a new Component instance to be created). Once this occurs, React looks at the instance being removed and its children. 5 | 6 | ## Using `componentWillUnmount()` 7 | Just like the rest of our life cycle phases, the Death/Unmount phase has a method hook for us. This method allows us to do some cleanup before we are removed from the UI stack. Typically we want to reverse any setup we did in either `componentWillMount()` or `componentDidMount()`. 8 | 9 | For example, we would want to unregister any global/system/library events, destroy 3rd party UI library elements, etc. If we don't take the time to remove events we can create memory leaks in our system or leave bad references laying around. 10 | 11 |  12 | 13 | React starts with the Element being removed, for example **A.0**, and calls `componentWillUnmount()` on it. Then React goes to the first child (**A.0.0**) and does the same, working its way down to the last child. Once all the calls have been made, React will remove the Components from the UI and ready them for Garbage Collection. 14 | 15 | ***Up Next:*** [The Life Cycle Recap](the_life_cycle_recap.md) 16 | -------------------------------------------------------------------------------- /life_cycle/lifecycle_methods_overview.md: -------------------------------------------------------------------------------- 1 | # React Life Cycle Methods Overview 2 | The React development team provides a series of hooks we can tap into at each phase of the life cycle. These method hooks inform us of where the Component is in the life cycle and what we can and cannot do. 3 | 4 | Each of the life cycle methods are called in a specific order and at a specific time. The methods are also tied to different parts of the life cycle. Here are the methods broken down in order and by their corresponding life cycle phase [^1]: 5 | 6 | ## Birth / Mounting 7 | 1. Initialize / Construction 8 | 2. `getDefaultProps()` *(React.createClass)* or `MyComponent.defaultProps` *(ES6 class)* 9 | 3. `getInitialState()` *(React.createClass)* or `this.state = ...` *(ES6 constructor)* 10 | 4. `componentWillMount()` 11 | 5. `render()` 12 | 6. Children initialization & life cycle kickoff 13 | 7. `componentDidMount()` 14 | 15 | ## Growth / Update 16 | 1. `componentWillReceiveProps()` 17 | 2. `shouldComponentUpdate()` 18 | 3. `componentWillUpdate()` 19 | 3. `render()` 20 | 4. Children Life cycle methods 21 | 5. `componentDidUpdate()` 22 | 23 | ## Death / Unmount 24 | 1. `componentWillUnmount()` 25 | 4. Children Life cycle methods 26 | 5. Instance destroyed for Garbage Collection 27 | 28 | The order of these methods are strict and called as defined above. Most of the time is spent in the Growth/Update phase and those methods are called many times. The Birth and Death methods will only be called once. 29 | 30 | ***Next Up***: [Birth/Mounting in-depth](birth_mounting_indepth.md) 31 | 32 | --- 33 | 34 | [^1] *Most of the methods are the same if you use either `React.createClass` or use ES6 classes, such as `class MyComponent extends React.Component`. A few are different, mainly around how instantiation/creation occurs. We will call these differences out throughout the chapter.* 35 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [Introduction](README.md) 4 | * [[WIP] React From the Inside Out](react_basics/introduction.md) 5 | * [The React Life Cycle](life_cycle/introduction.md) 6 | * [Life Cycle Methods Overview](life_cycle/lifecycle_methods_overview.md) 7 | * [Birth/Mounting In-depth](life_cycle/birth_mounting_indepth.md) 8 | * [Initialization & Construction](life_cycle/birth/initialization_and_construction.md) 9 | * [Pre-Mounting with componentWillMount()](life_cycle/birth/premounting_with_componentwillmount.md) 10 | * [Component render()](life_cycle/birth/component_render.md) 11 | * [Managing Component Children and Mounting](life_cycle/birth/managing_children_components_and_mounting.md) 12 | * [Post-Mount with componentDidMount()](life_cycle/birth/post_mount_with_component_did_mount.md) 13 | * [Growth/Update In-depth](life_cycle/growth_update_indepth.md) 14 | * [Updating and componentWillReceiveProps()](life_cycle/update/component_will_receive_props.md) 15 | * [Using shouldComponentUpdate()](life_cycle/update/using_should_component_update.md) 16 | * [Tapping into componentWillUpdate()](life_cycle/update/tapping_into_componentwillupdate.md) 17 | * [Re-rendering and Children Updates](life_cycle/update/rerendering_and_children_updates.md) 18 | * [Post-Render with componentDidUpdate()](life_cycle/update/postrender_with_componentdidupdate.md) 19 | * [Death/Unmount In-depth](life_cycle/death_unmounting_indepth.md) 20 | * [The Life Cycle Recap](life_cycle/the_life_cycle_recap.md) 21 | * [Component Evolution and Composition](patterns/component_evolution_and_composition.md) 22 | * [The Evolution of a List Component](patterns/the_evolution_of_a_list_component.md) 23 | * [Rendering different content](patterns/rendering_different_content.md) 24 | * [Higher Order Components](patterns/higher_order_components.md) 25 | * [About the Authors](about_the_authors.md) 26 | 27 | -------------------------------------------------------------------------------- /life_cycle/introduction.md: -------------------------------------------------------------------------------- 1 | # The React Life Cycle 2 | One of the defining factors of a life form is its life cycle. The common path is Birth, Growth into maturity and then the inevitable Death. UI applications often follow a similar path. When the application is first started, we consider this Birth. The users interacts with application, which is Growth. Eventually, the application is closed or navigated away from, leading to Death. 3 | 4 | Within the application, elements also follow this pattern. In the world of React, these elements are our Components. The Component life cycle is a continuous process, which occurs throughout the overall life of our application. Understanding this process can lead to faster and consistent development, easier optimization and improved overall application health. 5 | 6 | ## Life cycle phases in React components 7 | Not all UI systems enable a life cycle pattern. This doesn't mean that a system is better or worse if a life cycle is or isn't implemented. All a life cycle does is provide a specific order of operation and a series of hooks to tie into said system. The React life cycle follows the common Birth, Growth, and Death flow. The React team has provided a series of methods you can implement/override to tap into the process. 8 | 9 | ### [Phase 1: Birth / Mounting](birth_mounting_indepth.md) 10 | The first phase of the React Component life cycle is the Birth/Mounting phase. This is where we start initialization of the Component. At this phase, the Component's `props` and `state` are defined and configured. The Component and all its children are mounted on to the Native UI Stack (DOM, UIView, etc.). Finally, we can do post-processing if required. The Birth/Mounting phase only occurs once. 11 | 12 | ### [Phase 2: Growth / Update](growth_update_indepth.md) 13 | The next phase of the life cycle is the Growth/Update phase. In this phase, we get new `props`, change `state`, handle user interactions and communicate with the component hierarchy. This is where we spend most of our time in the Component's life. Unlike Birth or Death, we repeat this phase over and over. 14 | 15 | ### [Phase 3: Death / Unmount](death_unmounting_indepth.md) 16 | The final phase of the life cycle is the Death/Unmount phase. This phase occurs when a component instance is unmounted from the Native UI. This can occur when the user navigates away, the UI page changes, a component is hidden (like a drawer), etc. Death occurs once and readies the Component for Garbage Collection. 17 | 18 | ***Next Up:*** [Life Cycle Methods Overview](lifecycle_methods_overview.md) 19 | -------------------------------------------------------------------------------- /patterns/component_evolution_and_composition.md: -------------------------------------------------------------------------------- 1 | # Component Evolution and Composition 2 | Component reuse and composability are some of the core tenets of React development. As our applications scale, development time can be dramatically reduced through this process. Yet, creating reusable Components takes planning and understanding to support multiple use cases. 3 | 4 | Understanding the intention of the Component is the first step towards reuse. Sometimes, we know a Component will be used in many different ways from the start. In those situations, we can plan for the different scenarios right away. In other situations, Component intentions will change over the lifespan of the application. Understanding how to evolve a Component is just as important as understanding how to create reusability. 5 | 6 | ##The Application Architecture process 7 | 8 | Let's take a quick moment and discuss the process of application architecture. We often hear about over-architected systems. This often occurs when we try to plan for every possible scenario that could ever occur through the life of an application. To try and support every conceivable use is a fools errand. When we try to build these systems we add unnecessary complexity and often make development harder, rather then easier. 9 | 10 | At the same time, we don't want to build a system that offers no flexibility at all. It may be faster to just build it without future thought, but adding new features can be just as time consuming later on. Trying to find the right balance is the hardest part of application architecture. We want to create a flexible application that allows growth but we don't want to waste time on all possibilities. 11 | 12 | The other challenge with application architecture is trying to understand our needs. With development, we often have to build out something to truly understand it. This means that our application architecture is a living process. It changes over time due to having a better understanding of what's required. Refactoring Components is critical to the success of a project and makes adding new features easier. 13 | 14 | Because of this process, we felt it is important to walk through the evolution of a Component. 15 | We will start with a naive approach to building a List Component and then walk through different refactorings to support reusability. More then likely, we would know early on that a List should be reusable. But, walking through the evolution process can help deepen our understanding of how to enable reusability. 16 | 17 | ***Up Next***: [The Evolution of a List Component](the_evolution_of_a_list_component.md) 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React In-depth: An exploration of UI development 2 | At [DevelopmentArc®](http://developmentarc.com) we have a love affair with UI application development. We truly enjoy the exploration of technologies and frameworks. This process helps us better understand the end-goals and complexity of the application stack. 3 | 4 | We discovered early on the need to apply true software development principles to the user interface. This discovery started a long time ago with technologies like Authorware/Toolbook and Director. Quickly we moved to HTML 1.0 and began to build systems with JavaScript frameworks like Prototype.js. With the release of the Flex framework, our focus again shifted to a new platform, Flash. 5 | 6 | For a majority, Flash was a negative experience and UI technology. While many arguments are true, we found Flash to be the most advanced cross-platform rendering system available at the time. Flex gave us the application framework necessary to build the large and complex applications clients were requesting. All the while, Flex lent itself to the management of large and diverse teams. Our obsession with Flex included a deep understand of the application and component life cycles, resulting in a 90-page white paper. The paper is still available and continues to be referenced today. With the collapse of the Flash Platform and Flex, we find ourselves back in HTML and JavaScript world. This time our obsession is [React.js](https://facebook.github.io/react/) 7 | 8 | Throughout the years we have continued to try and push the boundaries of UI technologies. Starting, in late 2014, we began initial research and then full adoption of [React.js](https://facebook.github.io/react/) for our UI layer in for web applications. 9 | 10 | The initial process of moving to React was a blend of excitement and at times, pure frustration. React brings in both existing UI paradigms and also new patterns that can take a bit of time to adjust your own mind-set to. Once we had fully grokked React, we found that it has opened the possibilities for our current and future projects. 11 | 12 | Our goal with this GitBook is to document our process, share our research and try to organize our experiences into a single living document. Too be honest, this is a pretty lofty goal. We may not achieve this goal, but hopefully we can get some helpful thoughts down. 13 | 14 | We have found the longer you write code, the more you learn and then shortly forget. This means that our writings are just as much for ourselves as for others. With that in mind we hope that as this document grows it will help you, just as much as it helped us to put our own thoughts down. 15 | 16 | *James & Aaron* 17 | -------------------------------------------------------------------------------- /life_cycle/birth/premounting_with_componentwillmount.md: -------------------------------------------------------------------------------- 1 | # Pre-mounting with `componentWillMount()` 2 | Now that the props and state are set, we finally enter the realm of Life Cycle methods. The first true life cycle method called is `componentWillMount()`. This method is only called one time, which is before the initial render. Since this method is called before `render()` our Component will not have access to the Native UI (DOM, etc.). We also will not have access to the children `refs`, because they are not created yet. 3 | 4 | The `componentWillMount()` is a chance for us to handle configuration, update our state, and in general prepare for the first render. At this point, props and initial state are defined. We can safely query `this.props` and `this.state`, knowing with certainty they are the current values. This means we can start performing calculations or processes based on the prop values. 5 | 6 | **Person.js [^1]** 7 | ```javascript 8 | import React from 'react'; 9 | import classNames from 'classnames'; 10 | 11 | class Person extends React.Component { 12 | constructor(props) { 13 | super(props); 14 | this.state = { mode: undefined } ; 15 | } 16 | 17 | componentWillMount() { 18 | let mode; 19 | if (this.props.age > 70) { 20 | mode = 'old'; 21 | } else if (this.props.age < 18) { 22 | mode = 'young'; 23 | } else { 24 | mode = 'middle'; 25 | } 26 | this.setState({ mode }); 27 | } 28 | 29 | render() { 30 | return ( 31 |