Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs I';I’我的反应有困难_Reactjs - Fatal编程技术网

Reactjs I';I’我的反应有困难

Reactjs I';I’我的反应有困难,reactjs,Reactjs,这是我在github上的第一篇帖子。我只会说很少的英语,所以我很抱歉。保持警惕。我想要那东西。请帮帮我 这是我的应用程序页面 import React from 'react'; import {Provider} from 'react-redux'; import Counter from './Counter'; import {createStore} from 'redux'; const initialState = { count : 0 }; function red

这是我在github上的第一篇帖子。我只会说很少的英语,所以我很抱歉。保持警惕。我想要那东西。请帮帮我

这是我的应用程序页面

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;
从“React”导入React;
从'react redux'导入{Provider};
从“./Counter”导入计数器;
从“redux”导入{createStore};
常量初始状态={
计数:0
};
函数缩减器(状态=初始状态,动作){
如果(action.type==“警报”){
警惕(“ahihi”);
}
返回状态
}
const store=createStore(reducer);
常量应用=()=>(
);
导出默认应用程序;
这是我的柜台

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)
从“React”导入React;
从“react redux”导入{connect}
从“redux”导入{bindActionCreators};
导出常量ahihi=()=>({
类型:“警报”
});
常量计数器=({ab})=>{
返回(
);
}
常数a=(调度)=>({
答:bindActionCreators(ahihi,快讯)
}
导出默认连接(a)(计数器)

运行警报。我想要那个东西。请帮助我连接。将
MapStateTrops
作为第一个参数。如果不需要,可以

export default connect(null, a)(Counter)
计数器
需要获取在
mapDispatchToProps
中定义的
a
,并将其用作
onClick
事件处理程序:

const Counter = ({a}) => {

        return (
                <div>
                        <button onClick={a} ></button>
                </div>
        );
}
const计数器=({a})=>{
返回(
);
}

当您运行代码时,当前会发生什么?您是否收到任何错误?您将操作定义为
ahihi
(使用
键入:“警报”
)您需要将
onClick
中的第二个
警报
替换为
ahihi
@HenryWoody请重新检查代码,您所说的是不正确的,只会混淆OP.@ManavM好的,看看UjinT34的回答,似乎
警报
应该实际上是
a
ab
实际上也应该是
a
。我怀疑我的评论是否会如此混乱,因为它至少会将OP指向使用不正确变量名称的解决方案的方向。虽然我同意
ALERT
是错误的,
ahihi
,但OP需要做的是要访问
connect
已注入以下答案所示组件的功能,您是我的英雄