鉴于此组件:
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
const NewGoalInput = props => {
return (
<input type="text" onKeyUp={handleKeyUp}/>
)
}
const handleKeyUp = (e) => {
if (e.key === "Enter") {
// TODO Add goal
}
}
export default NewGoalInput
Run Code Online (Sandbox Code Playgroud)
如何在不使用extends React.Component语法的情况下添加构造函数来定义状态?