Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using async have a problem #23

Open
zahrahajilary opened this issue Apr 20, 2019 · 0 comments
Open

using async have a problem #23

zahrahajilary opened this issue Apr 20, 2019 · 0 comments

Comments

@zahrahajilary
Copy link

zahrahajilary commented Apr 20, 2019

hi again
I want to use async and I just copy your example code, and I get my data from parent and passing to child with props , but i have memory exceed error , what should i do ?
I'm beginner in react :)

my error :
`
Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

`

and my code :
componentDidMount() { var treeData = this.props.treeData if(treeData !== ''){ if(treeData !== []){ var treeDataArray = [] console.log(treeData, 'treeData') treeData.forEach(element => { let newTreeObj = { id: element.pid, name: ${element.title} - ${element.entityTypeName}`
}
treeDataArray.push(newTreeObj)
})

        this.setState({
            data: treeDataArray
        })
        }
    }

}
render() {
return (

        <SuperTreeview
            data={this.state.data}
            onUpdateCb={(updatedData) => {
                this.setState({ data: updatedData });
            }}
            isCheckable={() => (false)}
            isDeletable={() => (false)}
            isExpandable={(node, depth) => (true)}
            onExpandToggleCb={(node, depth) => {

                const asyncNodeId = 3;
                if (node.id === asyncNodeId && node.isExpanded === true) {
                    // This will show the loading sign
                    node.isChildrenLoading = true;

                    setTimeout(() => {
                        const updatedData = cloneDeep(this.state.data);

                        // Remove loading sign
                        updatedData[asyncNodeId - 1].isChildrenLoading = false;

                        // Make sure node is expanded
                        updatedData[asyncNodeId - 1].isExpanded = true;

                        // Set Children data that you potentially
                        // got from an API response
                        updatedData[asyncNodeId - 1].children = [
                            {
                                id: 22,
                                name: 'Child 1'
                            },
                            {
                                id: 23,
                                name: 'Child 2'
                            }
                        ];

                        // Update state
                        this.setState({ data: updatedData })

                    }, 1700);
                }
            }}
            onCheckToggleCb={(nodes) => {
                const checkedNode = nodes[0];

                if (checkedNode.id === 5) {
                    const checkState = nodes[0].isChecked;

                    applyCheckStateTo(nodes);

                    function applyCheckStateTo(nodes) {
                        nodes.forEach((node) => {
                            node.isChecked = checkState
                            if (node.children) {
                                applyCheckStateTo(node.children);
                            }
                        })
                    }
                }
            }}
        />
    );
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant