import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; // 引入antd相关 import { LocaleProvider } from 'antd'; import zhCN from 'antd/lib/locale-provider/zh_CN'; import 'antd/dist/antd.css'; import { BrowserRouter } from 'react-router-dom'; import {Provider} from "react-redux"; import store from './store'; // ReactDOM.render(, document.getElementById('root')); ReactDOM.render(
, document.getElementById('root') ); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA serviceWorker.unregister();
App.tsx
import React, {Component} from 'react'; import './App.css'; import { Switch, Route } from 'react-router'; import { NavLink } from 'react-router-dom'; import { Layout } from 'antd'; import A from './pages/a'; import B from './pages/b'; import { Dispatch } from 'redux'; import { connect } from "react-redux"; const { Header, Footer, Sider, Content } = Layout; interface Props { cName: string, changeName?: any } interface State { name: string } class App extends Component { // constructor(props: Props){ // super(props); // } render() { console.log(this.props.cName); return (
import {createStore} from 'redux'; function toDo(state, action) { state = state || {name: 'tom'}; switch (action.type) { case 'CHANGE_NAME': return {...state, ...action.payload}; default: return state; } } let store = createStore(toDo); export default store;
page/a.tsx
import React, {Component} from 'react'; import { Button } from 'antd'; class A extends Component { render() { return (
) } } export default A;
page/b.tsx
import React, {Component} from 'react'; import { Avatar } from 'antd'; class B extends Component { render() { return (