Coder Social home page Coder Social logo

ccalvarez / thinking-in-react Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reactgraphqlacademy/thinking-in-react

0.0 1.0 0.0 4.93 MB

The goal of this exercise is to learn how to think in React, by https://reactgraphql.academy/

HTML 5.37% CSS 42.70% JavaScript 51.93%

thinking-in-react's Introduction

React Fundamentals / Thinking in React

Learning objectives

  • Differentiate between declarative and imperative programming
  • Identify what's state and which components should hold it
  • Determine when to lift state up

Teaching method

  1. We try to foster critical thinking.
    • ⬆️ Discovery ⬇️ Instruction
  2. We don’t explain everything you need to know before the exercise:
    • Learn by doing (and teaching ;)
    • The exercise is meant to help you build a mental model

More about our teaching method here.

Prerequisites

You need to be comfortable writing JavaScript and HTML to do this exercise. The exercise uses the following ES6 & ES5 features:

You need to have node and npm installed on your computer.

If you find this exercise too difficult

If you find the exercise too difficult we recommend you to do the following basic React course from freeCodeCamp before.

🥑 Before we start the exercise

Before you start, we are going to use the useState hook in this exercise.

import React, { useState } from 'react';

function Example() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

The goal of this exercise is to understand what's state and how to reason about it. The goal of this exercise is not to learn how the useState hook works. How we store the state is an implementation detail. The principles you'll learn in this exercise can be applied to classes & this.setState, hooks, and some other state management libraries.

Getting started

git clone https://github.com/reactgraphqlacademy/thinking-in-react
cd thinking-in-react
yarn
yarn start

🤸‍♀️ Exercise

  • 1. Refactor the “about” and “footer” sections by creating a function component for each. Make sure everything works. Hint, you can look at the src/components/Header.js as an example.

  • 2. Refactor the navbar by creating a Function Component. Pass the dependencies (toggleMenu in this case) via props. Make sure everything works by clicking on the "Training" button at the top right of the screen. Hint, you can look at the src/components/Header.js as an example (heads up, use curly brackets to pass a prop as a function)

  • 3. Refactor the books section in App.js by creating a new function component called Books. The <Books> component will have the JSX related to books. This task is a stepping stone, keep all the state in <App> and pass any needed state from <App> to <Books> via props. You'll refactor and improve this code again in the next task. Make sure everything works.

  • 4. Is there any state in App.js that should be in the <Books> component? Refactor <Books> if appropriate.

  • 5. Break <Books> down into two smaller components: <BookList> and <BookFilter>. <BookList> will be responsible for displaying the books. <BookFilter> will be responsible for filtering the books. Is there any state in <Books> that should be moved into <BookList> or <BookFilter>?

🏋️‍♀️ Bonus exercise

  • Can we move the isMenuOpen state inside the menu? Does it conflict with the idea of "lifting state up".
  • If you look at the React Profiler when you open and close the menu, is the whole app being rendered? If so, how can we avoid that and still lift the state up?

Articles and links

License

This material is available for private, non-commercial use under the GPL version 3.

thinking-in-react's People

Contributors

alexlobera avatar flexbox avatar ric9176 avatar evandyou avatar foxreymann avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.