Git Product home page Git Product logo

flux-todolist's Introduction

flux-todolist's People

Contributors

pepperpapa avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  avatar

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.