Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React + Typescript #18

Open
Garrett-Bodley opened this issue Apr 2, 2024 · 9 comments
Open

React + Typescript #18

Garrett-Bodley opened this issue Apr 2, 2024 · 9 comments

Comments

@Garrett-Bodley
Copy link
Owner

tech debt....

@gregsadetsky
Copy link
Collaborator

easiest would be to bootstrap a new project with vite with the typescript+react preset. then, just drop the index.js file in, and adjust as necessary. also, small note but in package.json , we can remove the tsc which checks that all code is really fully typescript. otherwise the deployment will fail (if all of the types aren't defined/used)

@Garrett-Bodley
Copy link
Owner Author

How would the migration work in terms of CI integration? How do I start rewriting using components/react but not break the live demo? Should I make a new branch and do the work there?

@gregsadetsky
Copy link
Collaborator

yeah no all good I'll fix it if it stops working

but it really does work pretty much out of the box.

do you want me to typescript/reactify the thing? I'll just push onto main and make sure deployments still work

@Garrett-Bodley
Copy link
Owner Author

Garrett-Bodley commented Apr 2, 2024

Just tried and pushed but it didn't build 😔

Maybe because I did bun install instead of node install ?

@gregsadetsky
Copy link
Collaborator

yeah maybe -- it looks like the package installation failed while deploying:

https://github.com/Garrett-Bodley/SHAlala/actions/runs/8516167812/job/23324816515

want to retry?

to create a fresh typescript/react repo with vite:

npm create vite@latest

pick typescript, pick react, then you'll get a bunch of files.

then you'll have to merge which is the annoying bit. overwrite the package.json with the new one you got (from vite), and overwrite most other files. don't forget to remove the "tsc && " from the package.json's build line, then try git pushing again to see if it deploys?

@Garrett-Bodley
Copy link
Owner Author

Got it to build! It was a package-lock.json issue that I think was caused by using bun create vite. Fixed by deleting node_modules and package-lock.json and calling node install.

Still unsure of how the process of migrating from the existing code to React components will work. Right now the site is just ignoring the react stuff. Do I need a div#root element? Should I add <script type="module" src="/src/main.tsx"/> to index.html?

@gregsadetsky
Copy link
Collaborator

ah yeah congrats on fixing!

yeah re: react -- if you npm create vite@latest into some temporary separate directory, you'll see the react project that it creates. and yeah, it's pretty much that - there's a root element, the <script gets included as a module, and there's an App.tsx (sorta) that bootstraps it all. or like an index.ts that starts react and then react starts in App.tsx

@Garrett-Bodley
Copy link
Owner Author

uhhhhhhh, how do I reactify + typescript this

There's a lot of state that I just throw around wherever or just hold in the DOM. Would you use a ContextProvider that has some sort of struct that holds all the state? I feel like I maybe need a hook/context provider for the synths and maybe another one for "use the short hash" boolean?

Or am I overcomplicating and I should just prop drill since things aren't going to get that nested anyway.

It has been a minute since I have done react

@gregsadetsky
Copy link
Collaborator

Yeah I'd start small/easy with just props for all of the separate components and the main app containing / managing / owning all of the state using useState vars

I think contextprovider mayy be overkill at this point (since you don't have like ... a login ............. yet (Shalala as a service???? Hahaha))

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

No branches or pull requests

2 participants