freactal
freactal copied to clipboard
Can't get the current state new value after effect
I have read some of the issues posted here but can't seems to understand it clearly so I decided to create it myself. Here's my code
<Form onSubmit={_handleSearching()}>
<Form.Input
type="text"
id="barcode"
icon="search"
placeholder="Search barcode..."
/>
</Form>
Current state value will appear here and will update each form submission
<Step
icon="inbox"
title={"Indibox : " + state.indibar}
description="date processed: "
/>
However getting the state a value is behind like this doing a console.log
const _handleSearching = event => {
event.preventDefault();
const barcode = document.getElementById("barcode").value; //Z09J43H
effects.readBarcode(barcode);
console.log(state.indibar);
};
My state wrapper
const stateWrapperIndibox = provideState({
initialState: () => ({ indibar: "val" }),
effects: {
readBarcode: (effects, newVal) => state =>
Object.assign({}, state, { indibar: newVal })
}
});
Thanks
maybe try
effects.readBarcode(barcode).then( () => console.log(state.indibar))
Hi @ralphievolt, it looks like you're invoking your event handler immediately. Do things work differently if you pass _handleSearching vs _handleSearching()?