Here in the React Tutorial, they showcase an example situation similar to what you are dealing with, namely, state that needs to be visible for sub-components but shouldn't be repeated.
They pass the desired property into the props of the sub-component, which is what is generally done (in my experience) with properties that need to be passed down.
Here is some example code:
import React from 'react';
import SubComponent from 'SubComponent';
// MainComponent has prodStatus in props or state.
export default class MainComponent extends React.Component {
render() {
return <div><SubComponent prodStatus={this.state.prodStatus} /></div>;
}
}
Or if you prefer the function syntax (I am not familiar so please let me know if I made a mistake):
import React, { useState } from 'react';
import SubComponent from 'SubComponent';
// MainComponent has prodStatus in props or state.
export default function MainComponent(props) {
const [prodStatus, setProdStatus] = useState(/*prodStatus code*/);
return <div><SubComponent prodStatus={prodStatus} /></div>;
}
prodStatuscome from? Maybe it could be refactored to useuseReduceror maybe a simple function could be sufficient. But at least 10 times in a single component already seems suspicious to me. Also what is the semantic difference ofisSold = trueandisStillThere = false?