私はいくつかのコードに取り組んでいますが、このエラーで立ち往生しています。他のプロジェクトでそれが登場するのを見たことがないので、なぜここにあるのかわかりません。私は useEffect フックを使用しており、ユーザーがドロップダウンからオプションを選択したときにそれを更新したいと考えています。ユーザーがオプションを選択すると、次のエラーが発生しますTypeError: Assignment to constant variable.
。起こりえない定数を更新しようとしていると言っているのは理解していますが、その理由はわかりません。残念なことに、
コードを適切にレンダリングする方法を判断できませんが、次の 2 行は問題のあるコード行です。これらの後に、私が取り組んでいる完全なコードが続きます。
const [TitleId, setTitleId] = useState(0);
const TitleSelect = event =>{
console.log(event.target.value);
setTitleId=(32);
};
import React, {useState,useEffect} from 'react';
// import '../app.css';
const Header = props=> {
const [TitleList, setTitleList] = useState([]);
const [TitleId, setTitleId] = useState(0);
useEffect(()=>{
console.log('first start');
setTitleList(
props.data.map((title,index)=>({
title: title.title,
id: index
}))
)
},[])
const TitleSelect = event =>{
console.log(event.target.value);
setTitleId=(32);
};
let content = (
<select
onChange={TitleSelect}>
{TitleList.map(title=>(
<option key={title.id} value={title.id}>
{title.title}
</option>
))}
</select>)
return(content);
}
export default Header;
提案やアドバイスは大歓迎です。