I was able to run it as a local app on http://localhost:3001 using npm start, but if it is used on CodeSandbox or Stack Overflow snippet, the fetch fails. The same if I use the other API http://worldtimeapi.org/api/timezone/America/Los_Angeles
The error:
GET https://worldclockapi.com/api/json/pst/now net::ERR_CERT_COMMON_NAME_INVALID
Seems like it may be due to webpage on https and fetching data from API using http.
Example here as a live Stack Snippet:
function App() {
const [data, setData] = React.useState({});
React.useEffect(() => {
fetch("http://worldclockapi.com/api/json/pst/now")
.then(res => res.json())
.then(dataFetched => {
setData(dataFetched);
});
}, []);
return (
<div className="App">
<pre className="data">
{data.currentDateTime}
</pre>
</div>
);
}
ReactDOM.render(<App />, document.querySelector('.react'));
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div class='react'></div>
Anybody know why and how to make it work?
