0

I have a React Child component that looks like this:

const SingleProject =(props)=>{
    let data = projectData.VARIABLE_FROM_PROPS.projectDetails;
    let asideData = projectData.VARIABLE_FROM_PROPS.projectSideBar;

    useEffect(() => {
        console.log(props);
    }, []);
    return (<></>);

How can I use the value in props: props.pathname to get the projectDetails data.

Basically, if props.pathname is golly then I need to be able to get the data from projectData.golly.projectDetails.

Jose Manuel de Frutos
  • 1,040
  • 1
  • 7
  • 19
mcool
  • 457
  • 4
  • 29

1 Answers1

2

You can simply do projectData[VARIABLE_FROM_PROPS]["projectDetails"]

or

projectData[VARIABLE_FROM_PROPS].projectDetails

ldruskis
  • 779
  • 7
  • 20
  • Thanks! exactly what I needed – mcool Feb 07 '22 at 17:00
  • This is an **often-repeated duplicate**. Please don't post answers to obviously duplicate questions. Instead, vote to close as a duplicate of the canonical original. The purpose of SO's model is to avoid having hundreds of questions with near-identical answers, making it hard to find and curate good information, in favor of having one set (ideally) of well-curated answers we point all the questions at. – T.J. Crowder Feb 07 '22 at 17:00