react 中render与return 之间的变量(画红的问题)

react 中render与return 之间的变量(画红的问题)_第1张图片

 render() {
    const size = this.state.size;
    return (
      <div className={styles.main}>
        <RadioGroup value={size} onChange={this.handleSizeChange}>
          <RadioButton value="large">LargeRadioButton>
          <RadioButton value="default">DefaultRadioButton>
          <RadioButton value="small">SmallRadioButton>
        RadioGroup>
        <br />
        <br />
        <Button type="primary" size={size}>PrimaryButton>
        <Button size={size}>NormalButton>
        <Button type="dashed" shape="circle" size={size}>DashedButton>
        <Button type="danger" size={size} >DangerButton>

      div>
    );
  }

根据提示所说的要用对象的解构

 render() {
    const { size } = this.state;
    return (
      <div className={styles.main}>
        <RadioGroup value={size} onChange={this.handleSizeChange}>
          <RadioButton value="large">LargeRadioButton>
          <RadioButton value="default">DefaultRadioButton>
          <RadioButton value="small">SmallRadioButton>
        RadioGroup>
        <br />
        <br />
        <Button type="primary" size={size}>PrimaryButton>
        <Button size={size}>NormalButton>
        <Button type="dashed" shape="circle" size={size}>DashedButton>
        <Button type="danger" size={size} >DangerButton>

      div>
    );
  }

你可能感兴趣的:(react)