Search code examples
hookflowtype

How to annotate an inline function with flow?


So here is a link to my flow try, https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoAlgWwA5wE4AuYASgKYCGAxgQDRgDeYArgM6kDKB5BpYAvmCh44mMAHI8FamNRQmAO2ro48sNnKT5BABQBKeqjBGwlFSyIBtFgAtEAVWwATbqTpsC7WwgfOeALgAjODgYCnkAXgA+ADc4dEcAXTBw5jZOF20ochg2XVRUSQImPFUAHgBha3QYRyN3T3snF3D6eq8fFz5gSNQ+fIIAT2xeAAVhbBZkhlQ2xt9SPzAgkLCo2PiafL7ZBSUVMErqx21W0g92pp4+PzG4Cf1DY0Lissd0aLAVcph0SgBrFp6KKzbyXUjaczNSIAQkhPF0fEiAEZSsA3tEenwgA

but basically, if I pass a useState setter to a child, and I want to use flow to annotate the function, is there a way to do it without saying Function as the flow type?


Solution

  • The Props you're passing in needs to be updated to

    type Props = {
      setShowUpdate: (boolean => boolean) => void,
    }
    

    You're passing a function that accepts a boolean and returns a boolean that is then passed into another function that returns void.