Skip to content

Commit 919ded6

Browse files
author
sky
committed
fix: ts props error
1 parent 4377e96 commit 919ded6

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

app/web/framework/layout.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React, { Component } from 'react';
22
import { inject } from 'mobx-react';
33

4-
@inject('config')
4+
@inject('configStore')
55
export default class Layout extends Component<any> {
66
render() {
7-
const { config } = this.props;
8-
console.log('>>themeStyle', config.themeStyle);
7+
const { configStore } = this.props;
98
return <html>
109
<head>
1110
<title>{this.props.title}</title>
@@ -15,7 +14,7 @@ export default class Layout extends Component<any> {
1514
<meta name="description" content={this.props.description}></meta>
1615
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"></link>
1716
</head>
18-
<body style={{...config.themeStyle}}><div id="app">{this.props.children}</div></body>
17+
<body style={{...configStore.themeStyle}}><div id="app">{this.props.children}</div></body>
1918
</html>;
2019
}
2120
}

app/web/page/home/component/mobx/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component, CSSProperties } from 'react';
22
import { observable } from 'mobx';
33
import { Observer, observer, inject } from 'mobx-react';
44
import AppStore from './store';
5+
import { StoreProps } from '../../../../typings/type';
56

67

78
const info = observable({ text: "Mobx Observer Local Test" });
@@ -26,19 +27,19 @@ class LocalReactive extends Component {
2627
}
2728
}
2829

29-
@inject('config')
30+
@inject('configStore')
3031
@observer
31-
class MobXApp extends Component {
32+
class MobXApp extends Component<StoreProps> {
3233
store: AppStore;
3334
constructor(props) {
3435
super(props);
3536
this.store = new AppStore();
3637
}
3738

3839
render() {
39-
const { config } = this.props;
40+
const { configStore } = this.props;
4041
// [mobx] Dynamic observable objects cannot be frozen https://github.com/mobxjs/mobx/blob/master/CHANGELOG.md
41-
return <div style={{...config.themeStyle}}>
42+
return <div style={{...configStore!.themeStyle}}>
4243
<div style={{...this.store.style}} onClick={() => { this.store.plus()}}>点我:{this.store.number}</div>
4344
<LocalReactive></LocalReactive>
4445
</div>

app/web/page/home/component/tab/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import { Tabs } from 'antd';
33
import Header from '../../../../component/header/header';
4-
import { TabProps } from '../../../../framework/type';
4+
import { TabProps } from '../../../../typings/type';
55
import './index.css';
66

77
import MobXApp from '../mobx';
@@ -20,7 +20,7 @@ export class Tab extends Component<TabProps, any> {
2020
<div className="tab">
2121
<h1>{this.props.message.text}</h1>
2222
<Tabs defaultActiveKey="1" onChange={tabItemClick}>
23-
<TabPane tab="MobX" key="1"><MobXApp/></TabPane>
23+
<TabPane tab="MobX" key="1"><MobXApp /></TabPane>
2424
<TabPane tab="Tab 2" key="2">Content of Tab Pane 2</TabPane>
2525
<TabPane tab="Tab 3" key="3">Content of Tab Pane 3</TabPane>
2626
</Tabs>

app/web/page/home/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import ConfigStore from './store/config';
77
import Layout from '../../framework/layout';
88
// https://github.com/gaearon/react-hot-loader/issues/525
99
import { Tab } from './component/tab';
10-
import { TabProps } from '../../framework/type';
10+
import { TabProps } from '../../typings/type';
1111

1212
class App extends Component<TabProps, any> {
1313
render() {
1414
const stores = {
15-
config: new ConfigStore()
15+
configStore: new ConfigStore()
1616
};
1717
return <Provider {...stores}><Layout {...this.props}><Tab {...this.props} /></Layout></Provider>;
1818
}
@@ -24,7 +24,7 @@ function bootstrap() {
2424
return App;
2525
}
2626
const stores = window.stores = window.stores || {
27-
config: new ConfigStore()
27+
configStore: new ConfigStore()
2828
};
2929
const state = window.__INITIAL_STATE__;
3030
const root = document.getElementById('app');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import ConfigStore from '../page/home/store/config';
2+
13
export interface TabProps {
24
title: string;
35
keywords: string;
46
description: string;
57
message: {
68
text: string
79
};
10+
}
11+
12+
export interface StoreProps {
13+
configStore?: ConfigStore
814
}

0 commit comments

Comments
 (0)