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

generate .dataHooks and getStaticProps with the babel plugin #45

Open
paperdave opened this issue Mar 19, 2021 · 3 comments
Open

generate .dataHooks and getStaticProps with the babel plugin #45

paperdave opened this issue Mar 19, 2021 · 3 comments
Milestone

Comments

@paperdave
Copy link

Component.dataHooks always is an array of the data hooks from other components and the createDataHook function.

similarly getStaticProps, unless extra static props are desired, is also the same every time you write it: calling getDataHooksProps.

couldn't both of these be generated by the babel plugin? from my little experience from using babel, this shouldn't be too tricky to make, and it would reduce a lot of extra code that is copied from page to page, and eliminates the chance of missing a step.

the only issue here would be how to know weather to use getStaticProps or getServerSideProps, since you can't tell that from the hook usage themselves.

i'd like to try to implement this, maybe as an optional thing you need to enable. what are your thoughts?

@ricokahler
Copy link
Owner

I've thought of this too! It's a super cool idea and I'm definitely happy to explore some options around it. This lib already ships a babel plugin for code elimination so it could be pretty natural to add more babel magic.

To be upfront though, if we were to ship, it would definitely be under an experimental flag. I feel like there are some challenges to work out and it's hard to know if we got it right on the first try.

If you want to give it a go, I'd love to see the code but I can't promise you I'll merge it (but who knows, maybe this just works).

Feel free to change up any internal APIs to make it work (e.g. maybe a new createServerDataHook function can fix the problem you describe). We can start from an ideal API state and then work in backwards compatibility later.

@paperdave
Copy link
Author

modifying the api was my concern. the ambiguous "is it static props or server props" and also changing behavior in a very breaking way. i will give it a try, and it if doesnt get merged due to that, i can just keep it as a fork or something.

part of the motivation was from a work in progress thing very similar to this project, but implemented by modifying next itself. to be honest this is 100x cleaner than my approach, and my end goal is basically this project but with the extra automation i described.

i'll update this issue with any significant progress.

@ricokahler ricokahler added this to the v1.0.0 milestone Apr 13, 2021
@ricokahler
Copy link
Owner

ricokahler commented Apr 13, 2021

Update (for anyone interested): lots of progress on this one. @davecaruso's changes are currently present in the alpha branch and this is something I've committed to polishing for 1.0.0

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