Reactjs 传播不可复制实例的尝试无效。为了使其可移植,非数组对象必须具有[Symbol.iterator]()方法
我试图在react native with redux中测试和对象的useState值。 当我必须使用react-Redux在状态中存储值时,出现此错误。Reactjs 传播不可复制实例的尝试无效。为了使其可移植,非数组对象必须具有[Symbol.iterator]()方法,reactjs,react-native,redux,react-redux,Reactjs,React Native,Redux,React Redux,我试图在react native with redux中测试和对象的useState值。 当我必须使用react-Redux在状态中存储值时,出现此错误。 我想使用react native redux将笔记和数字存储在两个阵列中,并使用单个存储执行这两个操作。非常感谢您的帮助 组成部分: import React, { useState } from 'react' import { View, StyleSheet } from 'react-native' import { IconButt
我想使用react native redux将笔记和数字存储在两个阵列中,并使用单个存储执行这两个操作。非常感谢您的帮助 组成部分:
import React, { useState } from 'react'
import { View, StyleSheet } from 'react-native'
import { IconButton, TextInput, FAB } from 'react-native-paper'
import Header from '../components/Header'
function AddNote({ navigation }) {
const [noteTitle, setNoteTitle] = useState('')
const [noteValue, setNoteValue] = useState('')
function onSaveNote() {
navigation.state.params.addNote({ noteTitle, noteValue })
navigation.goBack();
}
return (
<>
<Header titleText='Add a new note' />
<IconButton
icon='close'
size={25}
color='white'
onPress={() => navigation.goBack()}
style={styles.iconButton}
/>
<View style={styles.container}>
<TextInput
label='Add Title Here'
value={noteTitle}
mode='outlined'
onChangeText={setNoteTitle}
style={styles.title}
/>
<TextInput
label='Add Note Here'
value={noteValue}
onChangeText={setNoteValue}
mode='flat'
multiline={true}
style={styles.text}
scrollEnabled={true}
returnKeyType='done'
blurOnSubmit={true}
/>
<FAB
style={styles.fab}
small
icon='check'
disabled={noteTitle == '' ? true : false}
onPress={() => onSaveNote()}
/>
</View>
</>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingHorizontal: 20,
paddingVertical: 20
},
iconButton: {
backgroundColor: 'rgba(46, 113, 102, 0.8)',
position: 'absolute',
right: 0,
top: 40,
margin: 10
},
title: {
fontSize: 24,
marginBottom: 20
},
text: {
height: 300,
fontSize: 16
},
fab: {
position: 'absolute',
margin: 20,
right: 0,
bottom: 0
}
})
export default AddNote
那我该怎么做呢。。
请帮助我..减速器必须返回新状态,而不是更新的参数:
// reducer
const INITIAL_STATE = {
note: [], //note array for save notes
number: [] // number array for save numbers
};
function notesReducer(state = INITIAL_STATE, action) {
switch (action.type) {
case ADD_NOTE:
return {
...state,
note: [
...state.note,
{
id: action.id,
note: action.note
}
]
};
case DELETE_NOTE:
const note = remove(state.note, obj => obj.id != action.payload);
return {...state, note};
case ADD_NUMBER:
return {
...state,
number: [
...state.number,
{
id: action.id,
number: action.number
}
]
};
case DELETE_NUMBER:
const number = remove(state.number, obj => obj.id != action.payload);
return {...state, number}
default:
return state
}
}
它不显示任何错误,但也不显示数字列表和注释列表。。
// reducer
const INITIAL_STATE = {
note: [], //note array for save notes
number: [] // number array for save numbers
};
function notesReducer(state = INITIAL_STATE, action) {
switch (action.type) {
case ADD_NOTE:
return {
...state,
note: [
...state.note,
{
id: action.id,
note: action.note
}
]
};
case DELETE_NOTE:
const note = remove(state.note, obj => obj.id != action.payload);
return {...state, note};
case ADD_NUMBER:
return {
...state,
number: [
...state.number,
{
id: action.id,
number: action.number
}
]
};
case DELETE_NUMBER:
const number = remove(state.number, obj => obj.id != action.payload);
return {...state, number}
default:
return state
}
}