input DX improvement opportunity

oliviertassinari
创建于
2018-04-28 11:48:53

Do you want to request a feature or report a bug?

A feature

What is the current behavior?

No warning is raised in the following snipped:

import React from "react";

export default class TextFields extends React.Component {
  state = {
    name: "Before timeout"
  };

  componentDidMount() {
    // emulate loading some data with AJAX
    setTimeout(() => {
      console.log("Updating name after timeout");
      this.setState({
        name: "After timeout"
      });
    }, 100);
  }

  render() {
    return <input id="name" label="Name" defaultValue={this.state.name} />;
  }
}

https://codesandbox.io/s/k248z9ro15

What is the expected behavior?

I believe we have the opportunity to raise a warning in development. It would inform users they can't update the defaultValue property. This problem was raised to my attention in mui-org/material-ui#11150.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React 16.3.2

3条回答
jquense
回复于
2018-04-28 12:02:24
#1

I see how this is generally a bug in this case however defaultValue can be updated to some effect, since it's the value used as the fallback in some situations, like a form reset

oliviertassinari
回复于
2018-04-28 12:06:50
#2

@jquense Alright, does it mean there is no DX improvement opportunity? Should we close this issue?

gaearon
回复于
2018-04-28 12:09:29
#3

Yeah I think we can’t warn without legit false positives.

当前位于第1页,总计3 条回复

推荐相似问题

The `ref.current` point to the wrong dom node

eg: {this.state.a ? <div ref={this.myRef} className="a"/> : <div className="b"/>} after state.a was set to false,when ac
讨论数 2
react
创建时间:2018-04-28 10:00:43

* { all: initial; } in css is breaking the react app

Hey guys, I have one problem working with any and even simple app of react. Here is the link of jsfield https://jsfiddle
讨论数 4
react
创建时间:2018-04-27 19:33:56

Coverage Support for JSX-Control-Statements

Conditional Rendering Components JSX-Control-Statement produces incorrect coverage in if / else branches. We are using i
讨论数 4
react
创建时间:2018-04-27 14:41:11

onClick event is not firing after enabling button via ref

Do you want to request a feature or report a bug? possible Bug, needs investigation What is the current behavior? When h
讨论数 4
react
创建时间:2018-04-27 07:45:47

Type is invalid. You likely forgot to export your component from the file it's defined in

I posted a SO question and created an issue on the Voyager project but thought I'd also document it here. I'm using comp
讨论数 3
react
创建时间:2018-04-27 07:00:26

Feature request: get a ref of a in memory dom element before mount.

Do you want to request a feature or report a bug? Feature What is the current behavior? currently, there isn't a great w
讨论数 3
react
创建时间:2018-04-26 19:08:01

Calling ReactDOM.render() many many times is slow

Do you want to request a feature or report a bug? Bug (?) What is the current behavior? Calling ReactDOM.render() many m
讨论数 9
react
创建时间:2018-04-26 18:42:43

Styles via className not reflected in print

Do you want to request a feature or report a bug? Not 100% sure, but might be a bug (or just something I'm not doing rig
讨论数 2
react
创建时间:2018-04-26 15:25:04

Conditional Rendering Such as JSX-Control-Statements

Do you want to request a feature or report a bug? Neither Conditional Rendering Components like JSX-Control-Statement ht
讨论数 4
react
创建时间:2018-04-26 15:03:46

Ref callback is not called before componentDidMount

Do you want to request a feature or report a bug? Bug What is the current behavior? ref callback is not executed before
讨论数 2
react
创建时间:2018-04-26 12:32:46