React sets the value of the select value of the parent component in the child component

< H2 > question < / H2 >

uses draft.js to build a rich text editor. When setting the font size function, a select selection box is used. The effect you want to achieve is that after the cursor selects Chinese text, the value of select becomes the font size of the selected text.
can now obtain the font size of the selected text, as long as the value of select is set to the selected font size, but the problem of Maximum update depth exceeded is encountered in the process of implementing this function. < H2 > related codes < / H2 >

// select
class SelectOptions extends React.Component {
  constructor() {
    super();
    this.onToggle = (e) => {
      e.preventDefault();
      console.log(this.props.style)
      this.props.onToggle(this.props.style);
    };
  }

  componentWillReceiveProps(nextProps) {
    // 
    // 
    if (nextProps.active) {
      nextProps.onSelectedHandler(nextProps.style)
    }
  }

  render() {
    return (
      <option
        value={this.props.style}
      >
        {this.props.label}
      </option>
    )
  }
}
// select
export default class FontSizeControl extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      value: "font16"
    }
  }

  handleChange = e => {
    this.setState({
        value: e.target.value
    }, () => {
      this.props.onToggle(this.state.value)
    });
  }

  onSelectedHandler = (selected) => {
    console.log(selected)
    this.setState({
      value: selected
    });
  }

  render() {
    return (
      <select
        onChange={this.handleChange}
        value={this.state.value}
      >
        {fontSizeTag.map(type =>
          <SelectOptions
            key={type.label}
            active={this.props.editorState.getCurrentInlineStyle().has(type.style)}
            label={type.label}
            onToggle={this.props.onToggle}
            style={type.style}
            onSelectedHandler={this.onSelectedHandler}
          />
        )}
      </select>
    );
  }
}
< H2 > error message < / H2 >

Mar.02,2021

the problem lies in SelectOptions component

componentWillReceiveProps(nextProps) {
    // 
    // 
    if (nextProps.active) {
      nextProps.onSelectedHandler(nextProps.style)
    }
  }

optimize the call onSelectedHandler timing

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf6e4d-3a3df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf6e4d-3a3df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?