Giter Club home page Giter Club logo

react_basics2's Introduction

Greeting

In React, you can build components and reuse them as often as you like. However, sometimes you want your components to be able to adapt to their environment, or other conditions, e.g. to have them display different types of content.

Let us use props to make components totally reusable!

Task

Create a Component with props

Look at the src/App.js file: the App component returns a default heading element. Replace this element with a custom Greeting component, which renders a greeting according to its props.

You can use the following hints as guideline:

  • Write the Greeting component inside of the App.js.
    • It accepts a prop called name (make sure to destructure it).
    • It returns an HTML element and uses the name prop to render "Hello, [name]!";
  • Inside of the return statement of your App component, replace the heading with your Greeting component and pass it a name prop with a value of your choice.

Conditional Rendering with props

Update your Greeting component to show "Hello, Coach!" if the name prop is equal to one of your coaches.

Notes

Development

CodeSandbox

Select the "Browser" tab to view this project.

Local development

To run project commands locally, you need to install the dependencies using npm i first.

You can then use the following commands:

  • npm run start to start the development server

๐Ÿ’ก This project requires a bundler. You can use npm run start to start the development server. You can then view the project in the browser at http://localhost:3000. The Live Preview Extension for Visual Studio Code will not work for this project.

react_basics2's People

Contributors

hannesoster avatar

Watchers

 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.