Skip to content

docs(examples): update create-react-app example#4347

Merged
darrachequesne merged 1 commit intosocketio:mainfrom
wdwang09:dev
Apr 20, 2022
Merged

docs(examples): update create-react-app example#4347
darrachequesne merged 1 commit intosocketio:mainfrom
wdwang09:dev

Conversation

@wdwang09
Copy link
Copy Markdown
Contributor

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

Previous create-react-app example can work normally. However, the useEffect hook will work multiple times when a new message arrives.

I add two console log to show the problem (line 14 and 26 in Gist).

before

Socket.IO callback will change the states, so the React component updates and call useEffect again.

New behavior

I fix this problem by passing a second argument to useEffect (doc). When states change, don't run useEffect again.

after

Other information (e.g. related issues)

Other change: I add the logo and other elements generated by create-react-app.

@darrachequesne darrachequesne merged commit 1f03a44 into socketio:main Apr 20, 2022
@darrachequesne
Copy link
Copy Markdown
Member

@wdwang09 good catch, thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants