Closed abelkbil closed 6 years ago
@andykog . Thanks . can you suggest what can be solution.
@abelkbil, you have to declare proptypes as optional, see the discussion: https://github.com/mobxjs/mobx-react/issues/256
@andykog Thanks for your support. I didn't use proptypes. And could you please mention where I have to make it optional.
@abelkbil, you may try in App.tsx:
interface Props {
- commonStore: commonStoreType;
+ commonStore?: commonStoreType;
}
Thanks for support In typescript ,
interface Props {
wid: string;
// tslint:disable-next-line:no-any
grid?: any;
dashboardStore?: DashboardStore;
widgetStore?: WidgetStore;
}
class Widget extends React.Component<Props, State> {
dashboardStore?: DashboardStore;
widgetStore?: WidgetStore;
constructor(props: Props) {
super(props);
// this.dashboardStore = this.injected.dashboardStore;
// this.widgetStore = this.injected.widgetStore;
this.dashboardStore = this.props.dashboardStore;
this.widgetStore = this.props.widgetStore;
this.widget = this.widgetStore.getWidget(this.props.wid) ;
This give a error
What I do now Please comment it it the right solution.
interface InjectedProps extends Props {
dashboardStore: DashboardStore;
widgetStore: WidgetStore;
}
constructor(props: Props) {
super(props);
this.dashboardStore = this.injected.dashboardStore;
this.widgetStore = this.injected.widgetStore;
get injected() {
return this.props as InjectedProps;
}
@andykog Thank you for consideration and time
@abelkbil, now widgetStore is optional, so typescript requires you to unwrap optional value somehow:
constructor(props: Props) {
super(props);
- this.dashboardStore = this.injected.dashboardStore;
- this.widgetStore = this.injected.widgetStore;
+ this.dashboardStore = this.injected.dashboardStore!;
+ this.widgetStore = this.injected.widgetStore!;
or
constructor(props: Props) {
super(props);
// this.dashboardStore = this.injected.dashboardStore;
// this.widgetStore = this.injected.widgetStore;
this.dashboardStore = this.props.dashboardStore;
this.widgetStore = this.props.widgetStore;
- this.widget = this.widgetStore.getWidget(this.props.wid) ;
+ this.widget = this.widgetStore!.getWidget(this.props.wid) ;
Okay. Got it. Very Thank You .
Thanks for the repo.
I am confused on how to pass the props typed
( React.Component <Props, State> )
for each components. Since I have defined the props of App, I get issue on index.tsx,Please help on this.
Index.tsx
App.tsx
CommonStore