Skip to content

setState( obj, callback) - callback called before state has mutated #6455

Closed
@wdiechmann

Description

@wdiechmann

I am fighting what used to be called 'a race condition' - I'm not sure what you guys call it in the React world :)

calling this snippet in a component

  reportArgs: (e) =>
    console.log( 'later: ' + @state.args)

  sendPrintRequest: (e) =>
    w = @state.url
    arg = @state.args
    arg = "komplex string manipulations goes here"
    @setState {wurl: w, args: arg}, console.log 'sooner ' + @state.args
    setTimeout @reportArgs, 5000

proves my point - I trust.

Either it is a 'noob observation - go do this instead' or a documentation glitch (as the docs says that the callback is called once the state is mutated) or, eventually, a bug

Obviously I'm rooting for #1 which would have me on my way in a jiffy - providing someone with a lot more knowledge of React would "stick it to me" so to speak :)

cheers,
Walther

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions