I have a component that has children of the same type as the component itself. I can also portray children, but children do not seem to be able to access their piece of the state. I am using React with Redux
export class Material extends React.Component { constructor(props) { super(props) this.renderChild = this.renderChild.bind(this) this.getNestedItems = this.getNestedItems.bind(this) } static propTypes = { parentId: PropTypes.number, id: PropTypes.number.isRequired, name: PropTypes.string.isRequired, subtext: PropTypes.string.isRequired, childIds: PropTypes.arrayOf(PropTypes.number.isRequired), fileType: PropTypes.string.isRequired }
In addition, I use ListItem from Material-ui (they end up being displayed inside the List component), and my code is heavily influenced by the tree example in the official repo repo. My condition looks like this:
const initialState = { 0: { id: 0, name: 'Root', subtext: 'Some subtext', fileType: '', childIds: [1] }, 1: { id: 1, name: 'Child', subtext: 'Child subtext', fileType: 'png', childIds: [] } }
The displayed state has the same structure as in the tree view example.
source share