Git Product home page Git Product logo

react-hooks-props-basics-lab's Introduction

Props Basics Lab

Learning Goals

  • Use props to make a dynamic component template
  • Pass props from a parent component to a child component

Introduction

Previously, we had been importing some data directly into each component that needed it using import. When we're working with React, we'll often access data by passing it down as a prop rather than importing it. This will be particularly true once we start working with data from external sources, such as APIs.

In this lab, you'll write React components and render them dynamically based on props they receive from their parent components. This will enable us to use components as templates with the ability to render variable content.

We'll continue building the portfolio site we started in the previous labs, and make the content dynamic by using props.

Here is an image of what we want once we are finished:

demo

...and here is a tree view of our component parent-child structure:

└── App
    ├── NavBar
    ├── Home
    └── About
        └── Links

Deliverables

It's recommended that you run npm start and work on this in the browser before running tests. Try to get your app to match the demo! Once you've built out the components below, run npm test to see if your code passes the tests.

App

In the App component, pass down data from the user object as props to the Home component so that it renders correctly. There is some starter code for you in the Home component that should give you a clue as to what props this component takes in.

App should also pass down a prop of bio to the About component.

Finally, App should also pass down the github and linkedin links to the About component, so that About can pass those props down to the Links component you will create.

About

Update the About component so that:

  • If a prop of bio is passed to this component, it is displayed inside of a <p> tag
  • If a prop of bio is not passed down, or if bio is an empty string, don't display the <p> tag
  • Hint: you'll need to do some conditional rendering here to determine whether or not to display the <p> tag

Links

Create a new component called Links. In this component, display the following:

  • an <h3> element with the text of "Links"
  • an <a> element with its href and text content set to URL of the user's Github link, passed down as a prop
  • a second <a> element with its href and text content set to URL of the user's LinkedIn link, passed down as a prop
  • Hint: make sure your <a> tags display the URL of the user's links as their text content so that it matches the demo image above

Resources

react-hooks-props-basics-lab's People

Contributors

danielseehausen avatar dependabot[bot] avatar ihollander avatar jlboba avatar kkterai avatar lizbur10 avatar maxwellbenton avatar rrcobb avatar sylwiavargas avatar thuyanduong-flatiron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-hooks-props-basics-lab's Issues

Content Clarity

Canvas Link

https://learning.flatironschool.com/courses/4542/assignments/150030?module_item_id=318021

Concern

Running through this lab, I spent a large amount of time trying to figure out why my test were failing despite the output appearing to be correct.

After digging through the tests I figured out that toBeInTheDocument() seems to only return the text content of the HTML tags and not the values of the various attributes. Upon closer inspection of the image on the lesson I do indeed see that it has the 'Links' URLs written out rather than the words 'GIthub' or 'LinkedIn', but I feel failing the tests on this is not really fair as the requirement only stated the links needed to be present.

If it's agreed that this path is a good one to go down, I'm happy to make the PR myself 😄

Additional Context

No response

Suggested Changes

I think a useful tweak would be to change the relevant tests to instead test for the href parameter. I'm definitely no React expert (yet!) but I tweaked the tests to produce what seemed to be what I was after like so:

test("passes 'github' to <Links> as a prop, via <About>", () => {
  const {container} = render(<App />);
  const a = container.querySelector(`a[href="${user.links.github}"`)
  expect(a).toBeInTheDocument();
  expect(a.tagName).toEqual("A");
});

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.