質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Material-UI

Material-UIは、Material Designを利用可能なオープンソースのReact向けUIコンポーネントキットです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

3036閲覧

【React】エラー表示『styles' is not defined no-undef』を改善したい

edu

総合スコア35

Material-UI

Material-UIは、Material Designを利用可能なオープンソースのReact向けUIコンポーネントキットです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2021/12/18 06:14

編集2021/12/20 14:36

reactでwebフォームを作成しています。

『'styles' is not defined no-undef'』という表示を改善したいです。

importをしても、スペルも確認したのですが、改善しません。
何方かアドバイスをお願いします。

試したこと
① 'styles' is not defined no-undefで、検索をして、いろんなパターんのimportを試した。

Failed to compile. src/components/Basic.js Line 24:26: 'styles' is not defined no-undef Line 24:42: 'styles' is not defined no-undef Line 25:21: 'styles' is not defined no-undef Line 144:29: 'styles' is not defined no-undef Line 144:45: 'styles' is not defined no-undef
//src/Basic.js import React from "react"; import { Link } from "react-router-dom"; import { FormControl, FormControlLabel, FormLabel, InputLabel, Radio, RadioGroup, Select, } from "@mui/material"; import { motion } from "framer-motion"; const Basic = ({ basicProfile, setBasicProfile, isConfirm }) => { return ( <> <motion.div initial={{ scaleY: 0 }} animate={{ scaleY: 1 }} exit={{ scaleY: 0 }} transition={{ duration: 0.5 }} > <div style={{ ...styles.page, ...styles.Basic }}> <p style={styles.copy}>お客様の情報を入力して下さい</p> <div style={{ textAlign: "center" }}> <FormControl component="fieldset"> <FormLabel component="gender">- 性別 -</FormLabel> {isConfirm ? ( <span>{basicProfile?.gender === "male" ? "男性" : "女性"}</span> ) : ( <RadioGroup row aria-label="gender" name="row-radio-buttons-group" value={basicProfile.gender} onChange={(evt) => setBasicProfile((state) => { return { ...state, gender: evt.target.value }; }) } > <FormControlLabel value="male" control={<Radio />} label="男性" /> <FormControlLabel value="female" control={<Radio />} label="女性" /> </RadioGroup> )} </FormControl> </div> <div style={{ textAlign: "center" }}> <FormLabel component="legend">- 生年月日 -</FormLabel> <FormControl sx={{ m: 1, minWidth: 120 }}> <InputLabel htmlFor="grouped-native-select">year</InputLabel> {isConfirm ? ( <span>{basicProfile.year}</span> ) : ( <Select native defaultValue="" id="grouped-native-select" label="Grouping" value={basicProfile.year} onChange={(evt) => setBasicProfile((state) => { return { ...state, year: evt.target.value }; }) } > <option aria-label="None" value="" /> <optgroup label="year"> {Array.from(Array(2020), (_, num) => ( <option key={num} value={num + 1990}> {num + 1990} </option> ))} </optgroup> </Select> )} </FormControl> <FormControl sx={{ m: 1, minWidth: 120 }}> <InputLabel htmlFor="grouped-native-select">month</InputLabel> {isConfirm ? ( <span>{basicProfile.month}</span> ) : ( <Select native defaultValue="" id="grouped-native-select" label="Grouping" value={basicProfile.month} onChange={(evt) => setBasicProfile((state) => { return { ...state, month: evt.target.value }; }) } > <option aria-label="None" value="" /> <optgroup label="month"> {Array.from(Array(12), (_, num) => ( <option key={num} value={num + 1}> {num + 1} </option> ))} </optgroup> </Select> )} </FormControl> <FormControl sx={{ m: 1, minWidth: 120 }}> <InputLabel htmlFor="grouped-native-select">day</InputLabel> {isConfirm ? ( <span>{basicProfile.day}</span> ) : ( <Select native defaultValue="" id="grouped-native-select" label="Grouping" value={basicProfile.day} onChange={(evt) => setBasicProfile((state) => { return { ...state, day: evt.target.value }; }) } > <option aria-label="None" value="" /> <optgroup label="day"> {Array.from(Array(31), (_, num) => ( <option key={num} value={num + 1}> {num + 1} </option> ))} </optgroup> </Select> )} </FormControl> </div> <Link style={{ ...styles.copy, ...styles.link }} to="/Questionnaire"> 次へ </Link> </div> </motion.div> </> ); }; export default Basic;

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

実際、このファイルの中のどこにもstylesが定義されてないのに使おうとしているからじゃないでしょうか。

どこかに以下のようなモノが必要です。

javascript

1const styles = { 2 page: { 3 // margin: '0' とか 4 }, 5 Basic: { 6 7 }, 8 copy: { 9 10 }, 11 link: { 12 13 } 14}

このファイル内に独自で上記を書いてスタイル定義するか、別のページがあるなら、そちらではどうやってstyle定義してるのかを見てそれを真似る(またはexportされてるならimportする)とかして、stylesを用意すればよいと思います。

投稿2021/12/20 15:03

umau

総合スコア805

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

edu

2021/12/21 12:10

umauさん、アドバイス、ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問