tamagui / tamagui

Style React fast with 100% parity on React Native, an optional UI kit, and optimizing compiler.
https://tamagui.dev
MIT License
10.23k stars 415 forks source link

[Documentation] Changing package manager does not change the command on other code block #2640

Closed romain-trotard closed 2 weeks ago

romain-trotard commented 2 weeks ago

Hello :)

Current Behavior

Currently, we can change the package manager (thanks to tabs) to have the right command to execute.

It changes the selected package manager for every code block, but the command does not change for other code block.

Reproduction video

Expected Behavior

The command should changed in function of the selected package manager for all code blocks.

The reason is that there is a local state for the command in the getBashCommand file. I think this state should be removed, because the source of truth should be the selected tabs (which is stored on the local storage) and the command, in my opinion, should be calculated on the render.

I have made a commit on a fork https://github.com/romain-trotard/tamagui/commit/5503296d9721d09266c032a69f0618c5006984e4. I will be very pleased to open a PR :)

ps: I think it's possible to do another solution: state up every state of the RowingTabs components in a hook (getBashCommand would be transformed into a hook), and use it in the DocCodeBlock component. But, I think there are some drawbacks like extracting the logic of the RowingTabs. The positive point would be that the useEffect I added would be removed.

Tamagui Version

Production environment: https://tamagui.dev/docs/intro/installation

Platform (Web, iOS, Android)

Web: chrome.

Reproduction

- Go to https://tamagui.dev/docs/intro/installation
- Change the package manager on the first code block -> it changes the command
- See that it has changed the selected package manager on other code block, but the command does not have changed

System Info

No response

natew commented 2 weeks ago

Oof yea this was contributed and is my fault for merging in a sloppy state.

natew commented 2 weeks ago

Happy to accept the PR, and your suggestions sound right.

natew commented 2 weeks ago

Just pushed a simple fix for now. Actually looking at it its fine to keep as-is.