I'm trying to make a tree structure in react. I use redux to hold data. I'am trying render this render tree by method 'renderTree' but I do something wrong
Here is my code:
import React, { Component } from 'react'
import {treeActions} from '../_actions'
import { connect } from 'react-redux';
class TreePage extends Component {
componentDidMount() {
this.props.getTree()
}
renderTree(parentId) {
const nodes = this.items && this.items.filter(x => x.parentNodeId == parentId);
<ul>
{nodes && nodes.map((item) => {
<li>{item.name}</li>
item.subNodes && this.renderTree(item.NodeId)
})}
</ul>
}
render() {
const {items} = this.props.tree;
this.items = items
return(
<React.Fragment>
<h1>Hello World!</h1>
{this.renderTree()}
</React.Fragment>
)
}
}
function mapState(state){
return state;
}
const actionCreators = {
getTree: treeActions.getTree
}
const connectedApp = connect(mapState, actionCreators)(TreePage)
export {connectedApp as TreePage}
And here is the photo of items:
And here is the message from console
./src/TreePage/TreePage.js
Line 14:9: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 16:17: Expected an assignment or function call and instead saw an expression no-unused-expressions
Search for the keywords to learn more about each error.
What could be the problem?