About the problem of Mobx inject passing value?

according to the documentation, Mobx, wants to get and call parameters in the form of inject in the sub-component, but there is a undefined problem?

// Timer.ts
interface IProps {
  timerStore?: TimerStore;
}

interface State {}

inject("timerStore")
@observer
export default class Timer extends React.Component<IProps, State> {
  constructor(props: IProps) {
    super(props);
    this.state = {};

    this.onClickBtn = this.onClickBtn.bind(this)
  }

  public onClickBtn():void {
    const tStore = this.props.timerStore as TimerStore;
    console.log(tStore);   // undefined
  }

  public render() {
    const tStore = this.props.timerStore as TimerStore;
    console.log(tStore); // undefined

    return (
      <div onClick={this.onClickBtn}>Seconds passed: {1}</div>
    )
  }
}

in App.ts , we can get the data normally, but when the sub-component Timer.ts injects store through inject , the corresponding store, will be undefined . After checking many reasons, we don"t know what the problem is. Ask the building to help solve it?

Mar.13,2021

I can't answer this question. I'd like to ask the subject about the ts error during injection.
if I declare and configure optional attributes in interface, there will be an error in the following image, but if I do not configure the optional attribute, then the error will appear in the following figure, but if I do not configure the optional only declaration, the parent component will report that I did not send the wallData props and asked me to give him props, but this is not passed by the parent component in the first place.
clipboard.png
clipboard.png


babel configuration file needs to install 'babel-plugin-transform-decorators-legacy'' and 'babel-preset-stage-1', plug-ins
probably because the modifier @ dec is the latest syntax of es7 and needs to parse


try the next layer of Provider, div add attribute timerStore= {TimerStore} , I can do it this way. It feels like the parent-child component transfer


your child component Timer.ts inject is missing the @ symbol!

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-1bf11d6-31d6d.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-1bf11d6-31d6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?