<i id='XHbxl'><tr id='XHbxl'><dt id='XHbxl'><q id='XHbxl'><span id='XHbxl'><b id='XHbxl'><form id='XHbxl'><ins id='XHbxl'></ins><ul id='XHbxl'></ul><sub id='XHbxl'></sub></form><legend id='XHbxl'></legend><bdo id='XHbxl'><pre id='XHbxl'><center id='XHbxl'></center></pre></bdo></b><th id='XHbxl'></th></span></q></dt></tr></i><div id='XHbxl'><tfoot id='XHbxl'></tfoot><dl id='XHbxl'><fieldset id='XHbxl'></fieldset></dl></div>
        <tfoot id='XHbxl'></tfoot>

        <small id='XHbxl'></small><noframes id='XHbxl'>

        <legend id='XHbxl'><style id='XHbxl'><dir id='XHbxl'><q id='XHbxl'></q></dir></style></legend>
        • <bdo id='XHbxl'></bdo><ul id='XHbxl'></ul>
      1. 警告:此合成事件因性能原因而被重用,并与 &lt;input type=“checkbox";/&am

        Warning: This synthetic event is reused for performance reasons happening with lt;input type=quot;checkboxquot; /gt;(警告:此合成事件因性能原因而被重用,并与 lt;input type=“checkbox;/gt;)

      2. <tfoot id='hUtxl'></tfoot>

        • <legend id='hUtxl'><style id='hUtxl'><dir id='hUtxl'><q id='hUtxl'></q></dir></style></legend>

          • <small id='hUtxl'></small><noframes id='hUtxl'>

              <tbody id='hUtxl'></tbody>
              <bdo id='hUtxl'></bdo><ul id='hUtxl'></ul>

                <i id='hUtxl'><tr id='hUtxl'><dt id='hUtxl'><q id='hUtxl'><span id='hUtxl'><b id='hUtxl'><form id='hUtxl'><ins id='hUtxl'></ins><ul id='hUtxl'></ul><sub id='hUtxl'></sub></form><legend id='hUtxl'></legend><bdo id='hUtxl'><pre id='hUtxl'><center id='hUtxl'></center></pre></bdo></b><th id='hUtxl'></th></span></q></dt></tr></i><div id='hUtxl'><tfoot id='hUtxl'></tfoot><dl id='hUtxl'><fieldset id='hUtxl'></fieldset></dl></div>
                1. 本文介绍了警告:此合成事件因性能原因而被重用,并与 &lt;input type=“checkbox";/&gt;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在为一个类编写一个简单的 react-redux 待办事项示例,每次我选中和取消选中复选框输入时,都会在控制台中看到几条警告消息.

                  您可以在以下图片中看到警告.

                  我还对警告消息进行了谷歌搜索,但找不到任何有效的解决方案.另外,让我印象深刻的是,它看起来像是在尝试访问本机事件和 DOM 元素的每个属性.

                  这是具有输入复选框的演示组件的代码

                  类 TodoItem 扩展 React.Component {状态 = {已检查:假};处理复选框 = () =>{这个.setState({isChecked: !this.state.isChecked});};使成为() {const { todos, onItemClick } = this.props;常量 { isChecked } = this.state;返回 (

                  <ul>{todos.map((todo, id) => {返回 (<li key={id} onClick={onItemClick}><输入onChange={this.handleCheckbox}类型=复选框"已检查={isChecked}/><标签><跨度/>{todo.textInput}</标签></li>);})}</ul></div>);}}导出默认 TodoItem;

                  我也在 CodeSandbox 上上传了示例:https://codesandbox.io/s/k0mlxk1yqv

                  如果您想复制此错误,您需要将一个项目添加到待办事项列表中,然后单击复选框以选中和取消选中几次.

                  如果有人知道为什么此警告标志不断出现以及如何禁用它们,我将非常感谢您的意见:)

                  解决方案

                  这是因为在异步上下文中使用了隐式传递给 onItemClickevent.
                  正如 Andre Lemay 所说,您应该将您的需求分配给局部变量并引用它们.

                  就我而言,我有这个代码:

                  handleInput = e =>{//<-- e = 合成事件this.setState(state => ({//<-- 异步调用数据: {...状态.数据,[e.target.name]: e.target.value//<-- 这是导致警告的原因(e.target 在异步上下文中)}}));};

                  然后我改成:

                  handleInput = e =>{常量 { 名称,值 } = e.target;//<-- 移到异步上下文之外this.setState(状态 => ({数据: {...状态.数据,[名称]:值}}));};

                  I've been working on a simple react-redux todo example for a class and I came across several warning messages that show in the console everytime I check and uncheck a checkbox input.

                  You can see the warnings in the following images.

                  I also did a google search for the warning message but couldn't find any solution that works. Also, what stroke my attention was that it looks like it was trying to access every property of the native event, and DOM element.

                  This is the code for the presentational component that has the input checkbox

                  class TodoItem extends React.Component {
                    state = {
                      isChecked: false
                    };
                    handleCheckbox = () => {
                      this.setState({
                        isChecked: !this.state.isChecked
                      });
                    };
                    render() {
                      const { todos, onItemClick } = this.props;
                      const { isChecked } = this.state;
                      return (
                        <div>
                          <ul>
                            {todos.map((todo, id) => {
                              return (
                                <li key={id} onClick={onItemClick}>
                                  <input
                                    onChange={this.handleCheckbox}
                                    type="checkbox"
                                    checked={isChecked}
                                  />
                                  <label>
                                    <span />
                                    {todo.textInput}
                                  </label>
                                </li>
                              );
                            })}
                          </ul>
                        </div>
                      );
                    }
                  }
                  
                  export default TodoItem;
                  

                  I uploaded the example on CodeSandbox as well: https://codesandbox.io/s/k0mlxk1yqv

                  If you want to replicate this error you need to add an Item to the todo List and click the checkbox to check and uncheck a couple of times.

                  If anyone has any idea why this warning signs keep appearing and how to disable them I would appreciate your input very much :)

                  解决方案

                  This happened because the event implicitly passed to onItemClick is used in an asynchronous context.
                  As Andre Lemay said, you should assign your needs to local variables and reference them.

                  In my case, I had this code:

                  handleInput = e => { // <-- e = synthetic event
                    this.setState(state => ({ // <-- asynchronous call
                      data: {
                        ...state.data,
                        [e.target.name]: e.target.value // <-- this was causing the warnings (e.target is in an asynchronous context)
                      }
                    }));
                  };
                  

                  Then I changed it to:

                  handleInput = e => {
                    const { name, value } = e.target; // <-- moved outside asynchronous context
                  
                    this.setState(state => ({
                      data: {
                        ...state.data,
                        [name]: value
                      }
                    }));
                  };
                  

                  这篇关于警告:此合成事件因性能原因而被重用,并与 &lt;input type=“checkbox";/&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                    <tbody id='DZGVB'></tbody>

                  <tfoot id='DZGVB'></tfoot>

                    <small id='DZGVB'></small><noframes id='DZGVB'>

                    1. <i id='DZGVB'><tr id='DZGVB'><dt id='DZGVB'><q id='DZGVB'><span id='DZGVB'><b id='DZGVB'><form id='DZGVB'><ins id='DZGVB'></ins><ul id='DZGVB'></ul><sub id='DZGVB'></sub></form><legend id='DZGVB'></legend><bdo id='DZGVB'><pre id='DZGVB'><center id='DZGVB'></center></pre></bdo></b><th id='DZGVB'></th></span></q></dt></tr></i><div id='DZGVB'><tfoot id='DZGVB'></tfoot><dl id='DZGVB'><fieldset id='DZGVB'></fieldset></dl></div>

                      • <legend id='DZGVB'><style id='DZGVB'><dir id='DZGVB'><q id='DZGVB'></q></dir></style></legend>

                            <bdo id='DZGVB'></bdo><ul id='DZGVB'></ul>