I'm a beginner on Reactjs ans Javascript.
I read that create-react-app can access the public folder like this to get an image:
img src={process.env.PUBLIC_URL + '/img/logo.png'} />;
But this also works but cant find documentation about it:
let photo = '/img/logo.png';
and another thing is if I try to read a json file the same way it fails:
let someJson = process.env.PUBLIC_URL + 'resume.json';
test code
return (
<div className="App">
<header className="App-header">
<img src={photo} className="App-logo" alt="logo" />
<p>
{someJson.basics.name} // FAIL ...
</p>
</header>
</div>
);
json
{
"basics": {
"name": "Foo Bar"
}
}
Why can I get the image and not the json?