[英]Is it possible to use dynamic variables inside a const?
我覺得這是一個愚蠢的問題,但是否可以在以下代碼中使用動態變量:
const [viewport, setViewport] = useState ({
latitude:-8.683895,
longitude:115.152307,
width:800,
height:440,
zoom:16
});
我需要動態的緯度和經度,所以如下所示:
const [viewport, setViewport] = useState ({
latitude:{varLatitude),
longitude:{varLongitude},
width:800,
height:440,
zoom:16
});
請問這樣做的正確方法是什么? 干杯!
您可以簡單地定義不需要添加括號的變量:
const [viewport, setViewport] = useState ({
latitude:varLatitude,
longitude:varLongitude,
width:800,
height:440,
zoom:16
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.