0

I have a parent class which will pass props to a component class. These props are arrays {door, window, carpet, curtain} which I have imported from my ProductInformation.js

I seem to have solved my problem of my props not being defined. My logic was that I pass <ProductSquare arrayId = {door}/> which would be the array name and than the I would call this.props.arrayId.map get error of undefined because {door} was obviously undefined.

I solved it by importing my data into my parent class and passing the individual arrays itself to child component class.

My question: Is this a efficient way to pass array data like this; is there a better logic?

import {door, window, carpet, curtain} from './ProductInformation2.js'


<Tabs forceRenderTabPanel>
            <TabList>
              <Tab>Front</Tab>
              <Tab>Rear</Tab>
              <Tab>Side</Tab>
            </TabList>
            <TabPanel>
            <div className = 'tabAreaSelected'>
                <ProductSquare arrayId = {curtain}/>
                <ProductSquare arrayId = {door}/>
                <ProductSquare arrayId = {window}/>
                <ProductSquare arrayId = {carpet}/>
                
            </div>
          
</Tabs>

Here is my previous question

3
  • I'm not sure what you think the options are; if they need an array, they need an array. Commented Jun 21, 2018 at 18:48
  • Yeah maybe i'm overthinking it. I was wondering if maybe you can place all your array data in the component and call it somehow inside the component by giving the component a keyword prop so it know which array to render instead of passing the whole array... if that makes sense. Commented Jun 21, 2018 at 18:53
  • Sure, you can pass whatever you want. All you're doing is passing around references--what they reference is up to you. Ideally components should only get the data they care about, but without more details, it's difficult to know what <ProductSquare /> is or if it's getting only the data it cares about. Commented Jun 21, 2018 at 19:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.