I'm unable to pass data assigned to a const
through props in react-js. When I check the same in console.log
i see a null object.
Below is code for the function.
updateList() {
// temporary dictionary
const keywords = {}
const taxonomies = {}
const { master, selectedRank, selectedCategory } = this.state
console.log(`master[${selectedRank}][${selectedCategory}]`)
if (master && master[selectedRank] && master[selectedRank][selectedCategory]) {
console.log(`master[${selectedRank}][${selectedCategory}]`, master[selectedRank][selectedCategory])
const filterData = master[selectedRank][selectedCategory]
master[selectedRank][selectedCategory].forEach(d => {
keywords[d.keywordId] = d.keywordName;
taxonomies[d.taxId] = d.taxonomyName;
})
const keywordsOptions = Object.keys(keywords).map(key => { return { id: key, name: keywords[key] }; });
const taxonomyOptions = Object.keys(taxonomies).map(key => { return { id: key, name: taxonomies[key] }; });
this.setState({
filterData
})
console.log("Filtered Data", this.state.filterData)
this.setState({
keywordsOptions,
selectedKeywordsOptions: keywordsOptions.slice(),
taxonomyOptions,
selectedTaxonomyOptions: taxonomyOptions.slice(),
filterKeyword: [],
filterTaxonomy: [],
}, () => {
this.updateChart();
});
}
}
I want to pass the data assigned to const
filterData
through props to a component in another js file. Though I'm setting up the state within the function I always get a null object in console. When I'm pushing the const to console I see the associated data being displayed in console.
I tried various other ways but none of them seem to be working here.
Thanks in advance.
Regards,