flux-todolist's Introduction
flux-todolist's People
flux-todolist's Issues
Warning: TodoItem is changing a controlled input of type checkbox to be uncontrolled.
1.案例源码TodoItem.jsx中如下代码
return (
<li className={classNames({
"completed": todo.complete,
"editing": this.state.isEditing
})}
key={todo.id}>
<div className="view">
<input
className="toggle"
type="checkbox"
// 直接使用todo.complete, 控制台会有警告
// Warning: TodoItem is changing a controlled input of type checkbox
// to be uncontrolled.
checked={todo.complete}
onChange={this._onToggleComplete}
/>
input元素checked属性直接赋值**{todo.complete}**,这样的话如果双击编辑todo item后回车保存时,浏览器控制台会弹出如下警告
Warning: TodoItem is changing a controlled input of type checkbox to be uncontrolled.
该告警的意思是表示input元素的checked属性可能不是true或false,也可能是undefined,因此报了该警告,只要保证checked属性是否为true或false,就不会再报了。
2. 修正后的代码如下(TodoItem.jsx):
return (
<li className={classNames({
"completed": todo.complete,
"editing": this.state.isEditing
})}
key={todo.id}>
<div className="view">
<input
className="toggle"
type="checkbox"
// 直接使用todo.complete, 控制台会有警告
// Warning: TodoItem is changing a controlled input of type checkbox
// to be uncontrolled.
checked={todo.complete ? true : false}
onChange={this._onToggleComplete}
/>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.