curriculum icon indicating copy to clipboard operation
curriculum copied to clipboard

Rendering Techniques: Missing info on how props and components work, causing confusion.

Open hoomanhorsey opened this issue 9 months ago • 11 comments

Checks

Describe your suggestion

re: the section included in the heading: "Rendering a list of components in JSX"

which includes a code fragment:

_

function ListItem(props) { return

  • {props.animal}
  • }

    function List(props) { return (

      {props.animals.map((animal) => { return <ListItem key={animal} animal={animal} />; })}
    ); }

    function App() { const animals = ["Lion", "Cow", "Snake", "Lizard"];

    return (

    Animals:

    <List animals={animals} />
    ); }

    _

    and the following explanation:

    _"We have moved our

      element to a different component called <List />. It still returns the
        element, but we can do a lot more with it as a component.

        This component accepts a props which is an object containing the animals that we defined as a property when we wrote <List animals={animals} />. Do note that you can name it anything, for example, <List animalList={animals} />. You will still need to pass the animals to the property, but now you will use props.animalList instead of props.animals.

        We have also created a different component for the

      • element called <ListItem />, which also accepts props, and uses props.animal to render the text. It should now render the same thing."_

    Correct me if I'm wrong, but at nowhere does the original instruction describe how the component accepts a prop. Normally with a function you expect an argument to be included within brackets. Here a component accepts an argument simply by having it written immediately after the name of the component. This is very confusing to those unfamiliar with React if it isn't explained or made explicit. There's an assumption that one already knows how props work, showing but not explaining.

    I was really confused by this and resorted to chatGPT to explain it to me. The example is good. It can be followed. But the fact that this key piece of info is missing made me very confused and I got stuck on it for longer than I perhaps should have.

    Also, THANK YOU so much to you all for your volunteer work and contributions. The entire course is pretty amazing.

    Path

    Node / JS

    Lesson Url

    https://www.theodinproject.com/lessons/node-path-react-new-rendering-techniques

    (Optional) Discord Name

    n/a

    (Optional) Additional Comments

    No response

    hoomanhorsey avatar Mar 13 '25 04:03 hoomanhorsey

    ~~Isn't this how javascript functions define parameters in general? function List(props) says that this function has a parameter called props. So if you call List({animal: data}) you are passing this object as props parameter.~~

    ~~When we use brackets we are performing object destructuring on that passed object function List({animal}).~~

    ~~Both of these are native javascript things and have been taught before. The lesson also says that all you need to know for now is that props are just arguments passed to the function and you'll learn more later. Unless I'm mistaking you.~~

    Ignore the above I get what you mean now. The lesson has this paragraph

    This component accepts a props which is an object containing the animals that we defined as a property when we wrote <List animals={animals} />

    Which says that by writing animals = {animals} we defined animals as a property on the props object. Did you find this line confusing?

    GaneshS288 avatar Mar 13 '25 06:03 GaneshS288

    Yes the paragraph that you've mentioned is the area that I found confusing. Not sure if others have, but I certainly did!

    The function / component declaration is pretty clear, i.e. 'function ListItem(props)'.

    It's when that function / component is called inside what the function returns, i.e.

    .<.List animals={animals} /.>

    It's not clear to me that 'animals={animals}' is the argument being passed into the List component, as I don't think we've seen this syntax before. For example, if it was express '<List(animals={animals} />' it would make sense, disregarding that it wouldn't actually work.

    Apologies if my terminology is a bit loose. Still learning!

    edit: bits of code that I'm trying to quote keep on disappearing. Not sure why. I put random .s in there so it reproduces.

    hoomanhorsey avatar Mar 13 '25 08:03 hoomanhorsey

    I feel like the text is actually alright. But it perhaps could do with the addition of something like 'The prop is passed into the component by including it immediately after the name of the Component. We haven't seen syntax like this before, as with a function the arguments are typically enclosed with brackets. Here brackets are unnecessary', or something like that.

    hoomanhorsey avatar Mar 13 '25 08:03 hoomanhorsey

    Not related to the main issue but

    edit: bits of code that I'm trying to quote keep on disappearing. Not sure why. I put random .s in there so it reproduces.

    You need code blocks just like in Discord because < > has meaning in GitHub markdown.

    mao-sz avatar Mar 13 '25 09:03 mao-sz

    Not related to the main issue but

    edit: bits of code that I'm trying to quote keep on disappearing. Not sure why. I put random .s in there so it reproduces.

    You need code blocks just like in Discord because < > has meaning in GitHub markdown.

    Yes thank you for that. Apologies my initial question may be so nonsensical due to the fragments of code I've quoted. And thank you for the patience in reading my comment.

    hoomanhorsey avatar Mar 13 '25 10:03 hoomanhorsey

    @hoomanhorsey thanks for raising this issue.

    I think it's totally reasonable to add a small note clarifying this, maybe something along the lines of "props are just like function arguments, but we pass them to JSX elements much the same way that we pass attributes to regular HTML elements".

    wise-king-sullyman avatar Mar 19 '25 13:03 wise-king-sullyman

    This issue is stale because it has had no activity for the last 30 days.

    github-actions[bot] avatar Apr 19 '25 02:04 github-actions[bot]

    Hey @hoomanhorsey, just checking in - are you still working on this, or would you like us to give someone else a shot at it?

    KevinMulhern avatar May 26 '25 13:05 KevinMulhern

    Hey @KevinMulhern, thanks for chasing me up about this. Apologies for not attending to this sooner. I'm mildly embarrassed about this but my beginner brain has been somewhat overwhelmed by the current stuff I'm working on and I've not had a chance to figure out how to make changes to the material.

    I'd like to help out one day. But perhaps it's best for this one if I hand it over to someone else who knows how to make the changes!

    Thanks again.

    hoomanhorsey avatar May 27 '25 23:05 hoomanhorsey

    No worries @hoomanhorsey, I appreciate you getting back to us. Best of luck with your learning!

    KevinMulhern avatar May 30 '25 14:05 KevinMulhern

    Hello, I am doing The Odin Project and I am in the getting hired course now, so I am looking for my first time contribution. Reading this issue, I express my interest in doing what is suggested, that is, adding a small explanatory note.

    The original paragraph that says: "We will use props here, and you will learn more about them in a future lesson. For now, you just need to know that props are arguments that are passed into components. We will just be writing a short implementation."

    Can say this: "We will use props here, and you will learn more about them in a future lesson. For now, you just need to know that props are just like function arguments that are passed into components, but to pass them we use a syntax similar to how we pass attributes to HTML elements. As you can see in the following short implementation."

    With the best intention of helping, I look forward to being assigned this task. Thanks

    manelly67 avatar Jun 09 '25 20:06 manelly67

    This issue is stale because it has had no activity for the last 30 days.

    github-actions[bot] avatar Jul 10 '25 02:07 github-actions[bot]

    Sorry for the delay @manelly67, I've assigned this one to you!

    KevinMulhern avatar Jul 17 '25 20:07 KevinMulhern

    Thanks @KevinMulhern , working on it

    manelly67 avatar Jul 17 '25 20:07 manelly67