对于这样一个新手的问题,我很抱歉,但我如何能够实现在选项卡之间切换使用react。如何使用存储我的inital代码: App.js来再现这个逻辑
class App extends Component {
constructor(props) {
super(props);
this.state = { tab: 0 };
}
switchingTabs = (event, value) => {
this.setState({
tab: value,
});
};
render() {
return (
<div className="App">
<Container>
<AppBar className="bar" position="static">
<Tabs value={this.state.tab} onChange={this.switchingTabs}>
<Tab label="Commits Info"></Tab>
<Tab label="User info"></Tab>
</Tabs>
</AppBar>
<TabBackbone value={this.state.tab} index={0}></TabBackbone>
<TabBackbone value={this.state.tab} index={1}></TabBackbone>
<Content></Content>
</Container>
</div>
);
}Index.js
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
ReactDOM.render(<App />, document.getElementById("root"));我试着自己做,但我不知道如何出口到减速机
发布于 2021-08-24 17:07:38
听起来你刚刚开始使用Redux,这太棒了!
export interface IState {
tabNumber : number
}
export initialState : IState = {
tabNumber : 0
}需要定义reducer的
export function appReducer(state=initialState, action : AnyAction) : IState{
// state reduction logic here
}然后
export const store = createStore(appReducer); // import {createStore} from "redux";然后,
。
<Provider store={store}> {/* import {Provider} from "react-redux"; */}
<App/>
</Provider>也就是说,我会考虑你是否需要Redux。我通常使用React Context API,特别是在这样的情况下,上下文主要用于执行高阶函数的功能。
https://stackoverflow.com/questions/68910206
复制相似问题