前提・実現したいこと
現在、reactとsqlでウェブアプリケーションを作成しています。sqlから手に入れたデータをいろいろなところで使いたいので変数に保存しようと思ったのですが、変数の中身がundefinedになってしまいます。上のconsole.log(response.data)ではデータは取れているのですが、変数に保存されません。なにが悪いのでしょうか?回答お願いします。
該当のソースコード
const getEmployeeInfo = () => { Axios.post('http://localhost:3001/api/getEmployeeInfo',{ shopName:location.state.shopName }).then((response) => { console.log(response.data) return response.data }) } const employeeData = getEmployeeInfo() console.log(employeeData)
コンソール
undefind //employeeDataのconsole.log {...}{...} //Axios.post内のconsole.log
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/03/15 03:48