Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Can't get the current state new value after effect #68

Open
ralphievolt opened this issue Jul 5, 2017 · 2 comments
Open

Can't get the current state new value after effect #68

ralphievolt opened this issue Jul 5, 2017 · 2 comments

Comments

@ralphievolt
Copy link

ralphievolt commented Jul 5, 2017

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

@Jascha-Sundaresan
Copy link

maybe try

effects.readBarcode(barcode).then( () => console.log(state.indibar))

@divmain
Copy link
Contributor

divmain commented Oct 27, 2017

Hi @ralphievolt, it looks like you're invoking your event handler immediately. Do things work differently if you pass _handleSearching vs _handleSearching()?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants