Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ReactJS上使用mobx组织typescript_Reactjs_Typescript_Mobx - Fatal编程技术网

如何在ReactJS上使用mobx组织typescript

如何在ReactJS上使用mobx组织typescript,reactjs,typescript,mobx,Reactjs,Typescript,Mobx,我制作了如下的mobx商店。 我在store.js中声明了操作类型 import { action, observable } from 'mobx'; export class SignStore { @observable UserInformation: { email: ''; password: ''; }; @action handleChange = (e: any): void => { this.UserInformatio

我制作了如下的mobx商店。
我在store.js中声明了操作类型

import { action, observable } from 'mobx';

export class SignStore {
  @observable
  UserInformation: {
    email: '';
    password: '';
  };

  @action
  handleChange = (e: any): void => {
    this.UserInformation[e.target.id] = e.target.value;
  };
}
我将这个存储注入一个组件中。
我在这里声明了用户信息的类型。
但是'const{SignStore}=this.props;'这里,
招牌店说

类型“Readonly&Readonly”上不存在属性“SignStore”

import*as React from'React';
从“mobx react”导入{observer,inject};
接口信息{
电子邮件:字符串;
密码:字符串;
}
@注入('SignStore')
@观察者
类注册扩展了React.Component{
render(){
const{SignStore}=this.props;
返回(
注册
电子邮件
密码
);
}
}
导出默认注册;

在这种情况下,你能推荐一些建议吗?

除其他问题外,主要问题是
this.props
IUserInformation
类型,即
{email:string;password:string;}
然后尝试用
const{SignStore}=this.props显然
props
没有
SignStore
参数。为此,道具需要看起来像:
{email:string;password:string;SignStore:any}

我对mobx不是很熟悉,但似乎您至少需要一个ISignStore的界面:

interface ISignStore {
  UserInformation: IUserInformation;
  handleChange: (e: any) => void;
}
然后将其用于您的组件:

class SignUp extends React.Component<ISignStore>

非常感谢。它工作得很好。那是我必须再次申报的!
class SignUp extends React.Component<ISignStore>
const SignStore = this.props;