I am using MaterialUI
to build component Expanded
, where inside I have list of text fields.
I store data in redux.
reduxState = {
fieldName1:[
{
primaryText:"text1",
},
{
primaryText:"text2"
},
],
fieldName2:[
{
primaryText:"text1"
},
{
primaryText:"text2"
},
]
}
Each Exapanded
keeps a textField
of each fieldNameN
the component Exapanded
looks like this
function Expanded(props) {
const {onChange, title, list } = props
const CustomPaper = withStyles({
root:{
color: blue
}
})(Paper)
return (
<ExpansionPanel>
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
<Typography>{title}</Typography>
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<Grid container spacing={1} direction="row">
{list.map((item,i) =>
<CustomPaper key={i}>
<TextInput label="Main Text" value={item.primaryText} xs={12} onChange={(value) => onChange(value, i, 'primaryText')}/>
</CustomPaper >
)}
</Grid>
</ExpansionPanelDetails>
</ExpansionPanel>
);
}
Example of use
<Expanded
title={`Add FieldName1`}
list={reduxState.fieldName1}
onChange={onChangeSectionInfo('fieldName')}
/>
the onChangeSelectionInfo
function calls redux action updateSection
when typing
[formActionTypes.UPDATE_SECTION]: (state, action) => {
//ex. field-FieldName, value-"text1Updated", index=0, element="primaryText"
const { field, value, index, element } = action.payload;
return {
...state,
[field]: state[field].map((object, i) =>
i === index ? { ...object, [element]: value } : object
)
};
},
The problem is that I can only type one char, and then it unfocus the TextField. Is it the problem with redux, that it takes too long to update?
EDIT: The solution from here is not helping, I took out all the loops and still doesnt work