Samuel
@samuel.fm
this fun fact brought to you by the bug that caused me to simultaneously post 50 test posts yesterday
React@react.dev· 1 Nov 2024
did you know that you can conditionally exit an effect? this is useful if you want a subscription to only stay active while some condition is true, and to stay removed while that condition is false. a bit mindbending, but so it is with react!
a code block:

  React.useEffect(() => {
    if (!isActive) {
      return
    }
    textInputWebEmitter.addListener('emoji-inserted', onEmojiInserted)
    return () => {
      textInputWebEmitter.removeListener('emoji-inserted', onEmojiInserted)
    }
  }, [onEmojiInserted, isActive])

the if (!isActive) condition is highlighted as newly added code
3 3 110