我正在尝试创建一个简单的Formik表单。第一次使用复选框。我可以渲染出复选框,但无法选中任何一个。问题出在哪里?
export default function App() {
var lights = [{id:1, name:"a"}, {id:2, name:"a"}]
return (<div>
<h1>Select Lights</h1>
<Formik
initialValues={{
checked: [],
}}
onSubmit={(eve) => this.submit(eve)}
>
{({values}) => (
<form>
<div id="checkbox-group">Checked</div>
<div role="group" aria-labelledby="checkbox-group">
{lights.map((light) =>
<div>
<label>
<Field type="checkbox" key={light.id} name="checked" value={light.id}/>
{light.name}
</label>
</div>
)}
</div>
<button type="submit" onClick={(event => this.submit(event))}>Submit</button>
</form>
)}
</Formik>
</div>)
}