react-easy-state: Problem with re-rendering not triggered
I am using this amazing library but I have encountered a problem and can’t wrap my head around it:
I have this snippet in a big complex component:
replaceAll = () => {
if (store.currentObject.replaceData) {
const replaceData = store.currentObject.replaceData;
Object.keys(replaceData).forEach(placeholder => {
store.currentObject.content = store.currentObject.content.replace(
`"${this.placeholderImage}" data-img-id="${placeholder}"`,
`${replaceData[placeholder]}`
);
store.currentObject.html = store.currentObject.html.replace(
`"${this.placeholderImage}" data-img-id="${placeholder}"`,
`${replaceData[placeholder]}`
);
});
}
};
The store.currentObjectis used in the render method of the component, and it works in all the scenario. But when I do this replace, the changes does not trigger a re-render… what am I missing?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 26 (11 by maintainers)
No advantages now @solkimicreb , it was just a leftover from previous coding like:
as it allowed me then to
git grep ContextConsumerand quickly review where I was using the context component… pretty useless now! 😃Hi @ciaoben , Indeed I have rewritten this component and others in a similar fashion you show above, and it also worked:
It also looks elegant IMO… thanks!
Hi there! I started testing react-easy-state in one component and had to face a similar problem, that is no re-rendering after an async api call. Long story short I’ve just solved it with a tip from a different use case I found elsewhere. Basically after I added a key prop, the corresponding snippet re-renders on key changes.
So now my component ends with:
export default view(({ lang }) => (<Intro key={ state.intro.head } lang={ lang } />))
Inside <Intro /> I call an async function that updates the contents of state.intro.head which is initially empty.
Hope this helps!
Now that I solved it I intend to replace more bits of code I am still holding into a Context module. Cheers, Klaus
No problem for the slow answer, thank you instead! Tomorrow I will return to work on that codebase and will try to extract some real code to send you.
On Mon, 21 Jan 2019 at 17:39, Miklos Bertalan notifications@github.com wrote:
– Ben