I have a function in react where i want to do :
renderPost(data) {
const dateStr = new Date(data.pub_date).toLocaleString();
const img='empty'
if (data.header_image_url.url!=null) {
const img=data.header_image_url.url}
else {
const img="/app/frontend/img.png"}
return (
<div className="card mb-4">
<Link to={`/post/${data.id}`}> <img src={img} className="card-img-top" alt=""/> </Link>
But it's not working like python : the const img inside the {} in the if and else statements dont take effect and dont override my const variable declaration above.
How can i do that ?
constmeans, b) you are redeclaring the (block-scoped) variable over and over, c) a javascript tutorial may be useful to read, e.g. javascript.info