如何设置对象的初始状态 Redux 数组(图像信息列表)
How to Set initial state Redux array of object (list of images info)
我想为要上传到服务器的图像信息数组设置初始状态。
我正在使用 react-native-image-crop-picker
我要上传select张图片和immutable.js。
我当前的addImages初始状态
var InitialState = Record({
addImages:[],
})
示例图像数组
[
{
filePath: ../image1.jpg
description: image 1
},
{
filePath: ../image2.jpg
description: image 2
},
.......
]
问题是我如何列出图像属性的所有初始状态,因为它取决于有多少图像 selected?
you can push all the images in array and assign that array in array of initial state and whenever the images are selected you can dispatch a function that will call reducer to change that initial state array into array of selected images like this :
export default function (state:State = initialState, action:Action): State {
switch(action.type){
case SELECT_IMAGES:
return Object.assign({}, state, {
addImages: action.payload.selectedImages
});
并且此更改将反映在 newProps
中,您可以在组件的 componentWillReceiveProps(newProps)
中捕获它。
我想为要上传到服务器的图像信息数组设置初始状态。 我正在使用 react-native-image-crop-picker
我要上传select张图片和immutable.js。
我当前的addImages初始状态
var InitialState = Record({
addImages:[],
})
示例图像数组
[
{
filePath: ../image1.jpg
description: image 1
},
{
filePath: ../image2.jpg
description: image 2
},
.......
]
问题是我如何列出图像属性的所有初始状态,因为它取决于有多少图像 selected?
you can push all the images in array and assign that array in array of initial state and whenever the images are selected you can dispatch a function that will call reducer to change that initial state array into array of selected images like this :
export default function (state:State = initialState, action:Action): State {
switch(action.type){
case SELECT_IMAGES:
return Object.assign({}, state, {
addImages: action.payload.selectedImages
});
并且此更改将反映在 newProps
中,您可以在组件的 componentWillReceiveProps(newProps)
中捕获它。