无法识别的事件 React Native Redux

Posted

技术标签:

【中文标题】无法识别的事件 React Native Redux【英文标题】:Unrecognized event React Native Redux 【发布时间】:2020-10-20 14:46:33 【问题描述】:

我是 redux 的新手。我正在使用带有 react-native 的 redux。我刚刚创建了一个简单的应用程序,它在 redux 上存储了 RGB 颜色,我正在使用组件并更新状态。输出很好,但我的 cmd 窗口出现错误。我正在使用 Expo-CLI。 enter image description here

我的应用程序代码在这里 应用.js

import React from 'react';
import  View  from 'react-native';
import reducer from './src/reducers/Index'
import Provider from 'react-redux'
import createStore from 'redux'
import ColorTile from './src/component/ColorTile.js'
const store=createStore(reducer)
export default function App() 
  return (
    <Provider store=store>
      <View style=flex:1,justifyContent:"center",alignItems:'center'>
          <ColorTile />
      </View>
    </Provider> 
  );

Index.js 代码

import combineReducers from 'redux'
import rgbReducer from './rgbReducer'

const allReducer=combineReducers(
      rgb:rgbReducer
)
export default allReducer

export function Increment_red()
      return 
            type:'Increment_red'
      

export function Decrement_red()
      return
            type:'Decrement_red'
      

export function Increment_green()
      return 
            type:'Increment_green'
      

export function Decrement_green()
      return
            type:'Decrement_green'
      


export function Decrement_blue()
      return
            type:'Decrement_blue'
      

export function Increment_blue()
      return 
            type:'Increment_blue'
      


rgbReducer.js 代码(reducer 代码)

const color=red:34,green:89,blue:64
const no=10;
export default function(state=color,action)
      switch(action.type)
            case 'Increment_red':
                return  ...state,red:state.red+no 
            case 'Decrement_red':
                 return ...state,red:state.red-10
            case 'Increment_green':
                  return  ...state,green:state.green+no
            case 'Decrement_green':
                  return  ...state,green:state.green-no
            case 'Increment_blue':
                  return  ...state,blue:state.blue+no
            case 'Decrement_blue':
                  return  ...state,blue:state.blue-no
            default:
                  return state;

      


colorTile.js 代码(我使用 reducer 的组件)

import React from 'react'
import View,Text,Button from 'react-native'
import useDispatch,useSelector from 'react-redux'

const ColorTile=()=>
      const color=useSelector(state=>state.rgb)
      const dispatch=useDispatch()
      const red=color.red
      const green=color.green
      const blue=color.blue
      return(
            <View>
                  <View style=backgroundColor:`rgb($red,$green,$blue)`,height:200,width:200>
                  </View>
                  <Button 
                        title='incerase red'
                        onPress=()=>dispatch(type:'Increment_red')
                  />
                  <Button 
                        title='Decerase red'
                        onPress=()=>dispatch(type:'Decrement_red')
                  />
                  <Button 
                        title='incerase Green'
                        onPress=()=>dispatch(type:'Increment_green')
                  />
                  <Button 
                        title='Decerase Green'
                        onPress=()=>dispatch(type:'Decrement_green')
                  />
                  <Button 
                        title='incerase Blue'
                        onPress=()=>dispatch(type:'Increment_blue')
                  />
                  <Button 
                        title='Decerase Blue'
                        onPress=()=>dispatch(type:'Decrement_blue')
                  />
            </View>
      )


export default ColorTile

我在命令行上遇到错误

Unrecognized event: "type":"client_log","level":"log","data":["Running \"main\" with \"initialProps\":\"exp\":\"initialUri\":\"exp://192.168.225.192:19000\",\"manifest\":\"iconUrl\":\"http://192.168.225.192:19001/assets/./assets/icon.png\",\"version\":\"1.0.0\",\"xde\":true,\"updates\":\"fallbackToCacheTimeout\":0,\"sdkVersion\":\"38.0.0\",\"platforms\":[\"ios\",\"android\",\"web\"],\"hostUri\":\"192.168.225.192:19000\",\"slug\":\"rgb\",\"icon\":\"./assets/icon.png\",\"web\":\"favicon\":\"./assets/favicon.png\",\"loadedFromCache\":false,\"debuggerHost\":\"192.168.225.192:19001\",\"splash\":\"resizeMode\":\"contain\",\"backgroundColor\":\"#ffffff\",\"image\":\"./assets/splash.png\",\"imageUrl\":\"http://192.168.225.192:19001/assets/./assets/splash.png\",\"primaryColor\":\"#023C69\",\"orientation\":\"portrait\",\"isVerified\":true,\"env\":,\"id\":\"@anonymous/rgb-656b5292-c20f-401c-b1b3-6976f3c65d94\",\"bundleUrl\":\"http://192.168.225.192:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false\",\"packagerOpts\":\"https\":false,\"dev\":true,\"lanType\":\"ip\",\"hostType\":\"lan\",\"minify\":false,\"urlRandomness\":\"f3-muw\",\"name\":\"rgb\",\"ios\":\"supportsTablet\":true,\"developer\":\"tool\":\"expo-cli\",\"projectRoot\":\"E:\\\\react\\\\rgb\",\"mainModuleName\":\"node_modules\\\\expo\\\\AppEntry\",\"logUrl\":\"http://192.168.225.192:19000/logs\",\"assetBundlePatterns\":[\"**/*\"],\"shell\":false,\"rootTag\":711"]

【问题讨论】:

更新到 expo SDK 38 后我遇到了同样的问题。 【参考方案1】:

只需更新 EXPO CLI npm install -g expo-cli

【讨论】:

【参考方案2】:

你是对的。 请通过运行以下命令更新 expo 客户端 npm install -g expo-cli

【讨论】:

以上是关于无法识别的事件 React Native Redux的主要内容,如果未能解决你的问题,请参考以下文章

React-Native-Voice,如何将新的语音结果与之前的语音识别结果连接起来?

React Native 错误 - yarn' 不被识别为内部或外部命令

React-Native:无法触发 Native UIButton 触摸事件

出现错误 - 运行本机反应时无法识别的命令“run-android”,

无法识别的选择器 NSInvalidArgumentException:对于 IBAction?

AppDelegate setFullscreen:无法识别的选择器发送到实例