There is json in the project which contains the data that I need to display in the component. How to correctly access the json file in react and output data from json?
data.json
{
"dictionary": [
{
"index": "1",
"engwords": "Hello",
"ruswords": "Привет"
},
{
"index": "2",
"engwords": "How are you?",
"ruswords": "Как твои дела?"
},
{
"index": "3",
"engwords": "How old are you?",
"ruswords": "Сколько тебе лет?"
}
]
}
component.js
import React, {Component} from "react";
import "./style.scss";
const dictionary = require ('./../../dictionary/dictionary.json');
export default class Test extends Component {
render() {
return (
<div className="test">
{dictionary.map(elem => (
<p>{elem}</p>))}
</div>
);
}
};