[英]I'm having trouble with react
This is my first post on github .这是我在 github 上的第一篇文章。 I only speak very little English , So i so sorry .我只会说很少的英语,所以我很抱歉。 run ALERT .运行警报。 i want that thing .我想要那个东西。 Please help me请帮我
this is my App page这是我的应用程序页面
import React from 'react';
import {Provider} from 'react-redux';
import Counter from './Counter';
import {createStore} from 'redux';
const initialState = {
count : 0
};
function reducer( state = initialState, action){
if(action.type === "ALERT" ){
alert("ahihi");
}
return state
}
const store = createStore(reducer);
const App = () => (
<Provider store ={store}>
<Counter />
</Provider>
);
export default App;
this is my Counter page这是我的柜台页面
import React from 'react';
import {connect} from "react-redux"
import {bindActionCreators} from 'redux';
export const ahihi = () => ({
type: "ALERT"
});
const Counter = ({ab}) => {
return (
<div>
<button onClick={ALERT} ></button>
</div>
);
}
const a = (dispatch) =>({
a : bindActionCreators(ahihi, dispatch)
}
export default connect(a)(Counter)
run ALERT .运行警报。 i want that thing .我想要那个东西。 Please help me请帮我
connect
takes mapStateToProps
as first argument. connect
将mapStateToProps
作为第一个参数。 If you don't need this you can just如果你不需要这个,你可以
export default connect(null, a)(Counter)
Counter
needs to get a
defined in your mapDispatchToProps
and use it as onClick
event handler: Counter
需要在您的mapDispatchToProps
定义a
并将其用作onClick
事件处理程序:
const Counter = ({a}) => {
return (
<div>
<button onClick={a} ></button>
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.