如何使用 React.js 16 在服务器上呈现 "disabled" HTML 属性?
How to render the "disabled" HTML attribute on server with React.js 16?
我刚刚更新到 React.js 16
,我很难在 button
中使用简单的 HTML 属性。这是我的代码:
const disabled = this.props.disabled;
console.log(disabled);
return <button id="my-id" disabled={disabled}>Click!</button>;
console.log
在前端记录 true
,在后端记录 false
。在浏览器控制台上,我得到了这个:Warning: Prop 'disabled' did not match. Server: "null" Client: "true"
.
在 React Chrome 扩展中,我可以看到该道具实际上设置为 true
,因此它应该可以工作。它只有在我强制它更改为 false
然后在前端返回到 true
时才有效。
这曾经与 React.js 15.5.4
一起使用。我做错了什么/React.js 16
发生了什么变化?
迁移到 React.js 16
后,我们开始使用 hydrate
作为前端,元素没有更新,这是预期的行为。
问题实际上出在 redux-form
中,如此处所报告:https://github.com/erikras/redux-form/issues/2610
添加 pristine
的额外条件后,现在一切正常。
我刚刚更新到 React.js 16
,我很难在 button
中使用简单的 HTML 属性。这是我的代码:
const disabled = this.props.disabled;
console.log(disabled);
return <button id="my-id" disabled={disabled}>Click!</button>;
console.log
在前端记录 true
,在后端记录 false
。在浏览器控制台上,我得到了这个:Warning: Prop 'disabled' did not match. Server: "null" Client: "true"
.
在 React Chrome 扩展中,我可以看到该道具实际上设置为 true
,因此它应该可以工作。它只有在我强制它更改为 false
然后在前端返回到 true
时才有效。
这曾经与 React.js 15.5.4
一起使用。我做错了什么/React.js 16
发生了什么变化?
迁移到 React.js 16
后,我们开始使用 hydrate
作为前端,元素没有更新,这是预期的行为。
问题实际上出在 redux-form
中,如此处所报告:https://github.com/erikras/redux-form/issues/2610
添加 pristine
的额外条件后,现在一切正常。