Reactjs 是否可以在Redux形式的助手函数中指定初始值?
我已经读过了,但是我需要在我的类组件中的helper函数中进行一些数据转换。我在助手函数中执行此操作,因为我需要首先从this.props.match.params收集一些参数。这些参数有助于获取要以redux形式编辑的正确数据。提前谢谢。谢谢你的帮助Reactjs 是否可以在Redux形式的助手函数中指定初始值?,reactjs,redux,redux-form,Reactjs,Redux,Redux Form,我已经读过了,但是我需要在我的类组件中的helper函数中进行一些数据转换。我在助手函数中执行此操作,因为我需要首先从this.props.match.params收集一些参数。这些参数有助于获取要以redux形式编辑的正确数据。提前谢谢。谢谢你的帮助 function mapStateToProps(state){ // First I tried to do the transformations here // but I have no access to this.props
function mapStateToProps(state){
// First I tried to do the transformations here
// but I have no access to this.props.match.params
return {
data: state.data,
initialValues: {a: 'foo', b: 'faa'} //<== I believe I should insert initialValues here
}
如果需要从MapStateTrops中的组件访问道具,可以使用ownProps 我可以这样做:
function mapStateToProps(state,ownProps){
// Do the necessary transformations
const myData = state.data.settings
let dataToEdit, myObj = {}
if(myData){
// Get params
const {file,tree,branch,node} = ownProps.match.params
// Build path to data
dataToEdit = myData[file][tree][branch][node]
const arr = Object.entries(dataToEdit)
// We want to create a nice object from the messy data coming from an XML FILE :-/
arr.map((i)=>{
myObj[i[0]] = i[1]._text
})
}
// console.log(myObj)
return{
data: state.data,
initialValues: myObj
}
}
function mapStateToProps(state,ownProps){
// Do the necessary transformations
const myData = state.data.settings
let dataToEdit, myObj = {}
if(myData){
// Get params
const {file,tree,branch,node} = ownProps.match.params
// Build path to data
dataToEdit = myData[file][tree][branch][node]
const arr = Object.entries(dataToEdit)
// We want to create a nice object from the messy data coming from an XML FILE :-/
arr.map((i)=>{
myObj[i[0]] = i[1]._text
})
}
// console.log(myObj)
return{
data: state.data,
initialValues: myObj
}