I have a state
const [analysisData, setAnalysisData] = useState(false);
I am setting the data of this state in a function and when I console console.log(analysisData) I am getting the output as
{ID:1, ANALYSIS_NAME : "name1",
custodians:"[{\"ID\": 1, \"NAME\": \"abc\"},
{\"ID\": 2, \"NAME\": \"xyz\"},
{\"ID\": 3, \"NAME\": \"pqr\"}]"
};
When I try to display in HTML as below, I am getting error
const AnalysisList = () => {
return(<div>
<Panel>
{JSON.parse(analysisData.custodians).map((childData) => {
return (
<div>
{console.log(childData.NAME)}
</div>
)}
)}
<Panel>
</div>)
}
export default AnalysisList
I am trying to display "Name" inside the div in the above code.
How to display. Please help
AnalysisListdoes not have theanalysisDataanywhere in its scope . Can you add the complete code of yourAnalysisListcomponent ? . You are setting theanalysisDataas false initially but you are getting an object in the console log . There are many missing pieces in your question . Instead of console.log inside your div you just need to do<div{childData.NAME}</div>