💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
Provider这个组件的作用: 它是react-redux的核心组件,它可以将store提供给它里面的每一个组件 ~~~ import {Provider} from 'react-redux'; import store from './store'; const App ={ <Provider store={store}> <App/> </Provider/> } ~~~ 但是只提供是不行的,如果组件想和store连接,还需要connect组件 ~~~ //App.js组件 import {connect} from 'react-redux'; //怎么连接,connect方法接受三个参数 const mapStateToProps =(state)=>{ return { inputValue:state.inputValue } } const mapDispatchProps=(dispatch)=>{ return { changeInputValue(e){ const action = { type:'inputChange', value:e.target.value } dispatch(action) } } } export default connect(mapStateToProps,mapDispatchProps)(App) //mapStateToProps表示将store的数据和组件的数据作映射 //将dispatch方法和store中的数据作关联 mapDispatchProps // 可以让props的方法,派发action,操作store中的数据 ~~~