0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【React】JSX attributes must only be assigned a non-empty expressionの対処法

Last updated at Posted at 2021-08-29

症状

Reactでコンポーネントを作成していた時、以下のエラーが発生しました。 翻訳すると、「JSX属性には、空でない式のみを割り当てる必要があります」でした。
error
SyntaxError: 絶対パス JSX attributes must only be assigned a non-empty expression

該当のソースは以下です。

Hoge.jsx
export function Hoge () {
 function submitHandle() {
    return "Hoge"
  }

  return (
    <buttom onClick={}></buttom>
  )
} 

解決方法

buttomの中のonClickイベントの中身を指定することで解決しました。 エラー内容そのままで、jsx要素であるreturn内部のbuttomに何も指定されていなかったため、エラーが出ていたようです。
Hoge.jsx
export function Hoge () {
 function submitHandle() {
    return "Hoge"
  }

  return (
    <buttom onClick={() => submitHandle}></buttom>
  )
} 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?