ricokahler / next-data-hooks Goto Github PK
View Code? Open in Web Editor NEWUse `getStaticProps`/`getServerSideProps` as react-hooks
License: MIT License
Use `getStaticProps`/`getServerSideProps` as react-hooks
License: MIT License
It should be possible to attach more than just one datahook I believe. But I get an error. Can just one DataHook be delivered to getStaticProps()?
export const getStaticProps: GetStaticProps = async (context) => {
const dataHooksProps = await getDataHooksProps({
context,
dataHooks: ParagraphExample.dataHooks,
});
const dataHooksProps2 = await getDataHooksProps({
context,
dataHooks: BlogPost.dataHooks,
});
return {
props: { ...dataHooksProps, dataHooksProps2 },
};
I also tried:
dataHooks: [ParagraphExample.dataHooks, BlogPost.dataHooks].
Even though the peerDependencies
now include NextJS 12, a new package hasn't been released on npm yet. Thanks!
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@babel/plugin-transform-runtime
, @babel/preset-env
)create-next-app
, next
)@rollup/plugin-babel
, @rollup/plugin-node-resolve
, actions/checkout
, actions/setup-node
, codecov/codecov-action
, prettier
, react-error-boundary
, rollup
, typescript
)create-next-app
, next
).github/workflows/test.yml
actions/checkout v3
actions/setup-node v3
codecov/codecov-action v3
package.json
@babel/core 7.25.2
@babel/node 7.25.0
@babel/plugin-transform-runtime 7.24.7
@babel/preset-env 7.25.3
@babel/preset-react 7.24.7
@babel/preset-typescript 7.24.7
@ricokahler/exec 1.1.0
@rollup/plugin-babel 5.3.1
@rollup/plugin-node-resolve 13.3.0
@types/common-tags 1.8.4
@types/jest 29.5.12
@types/react 18.3.3
@types/react-dom 18.3.0
@types/react-test-renderer 18.3.0
@types/webpack 5.28.5
@typescript-eslint/eslint-plugin 8.1.0
@typescript-eslint/parser 8.1.0
@babel/eslint-parser 7.25.1
common-tags 1.8.2
create-next-app 13.4.19
eslint 8.57.0
eslint-config-react-app 7.0.1
eslint-plugin-flowtype 8.0.3
eslint-plugin-import 2.29.1
eslint-plugin-jsx-a11y 6.9.0
eslint-plugin-react 7.35.0
eslint-plugin-react-hooks 4.6.2
folder-hash 4.0.4
jest 28.1.3
next 13.4.19
prettier 2.8.8
react 18.3.1
react-dom 18.3.1
react-error-boundary 3.1.4
react-test-renderer 18.3.1
rollup 2.79.1
typescript 4.9.5
react ^16.8 || ^17 || ^18.0.0
next ^9.3 || ^10 || ^11.0.0 || ^12.0.0 || ^13.0.0
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?
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
Is this a known issue? I followed the tutorial and have no idea why this occurrs. Any ideas? Should I provide a github repo?
Great project! Tried to use it with my project, however, it was failing with an error Error: Could not find
NextDataHooksContext. Ensure
NextDataHooksProvider is configured correctly.
Tried to debug and ended up cloning the repo and running the example. First run, works (next 10.0.1), then proceeded to update Next to 10.1.3 (latest). Hit the exception
Thanks for the lib.
I wanted to implement this feature but had been confronted with 2 mature issues, that let me stick to simple function in the comp file, that will be called in a static function within a page.
The useHooks do not carry payloads… this is important to handle specific calls for specific instances of the same component in the same page.
The hook body is more like a static independent function without context… or index. This makes it hard to bind the data two the components if there are more than just one.
Are there any plans to modify or add payload features in the future ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.