-
Notifications
You must be signed in to change notification settings - Fork 33
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
Easy way to simplify pages, and satisfy FastRefresh #47
Comments
There are many scenarios where you can't use the My motivation with this template is to provide one solution that will reliably work 100% of the time, even when the code changes / grows. |
Hi, thanks for your answer.
Could you give me some link/doc where I can find some (noob here)?
I've tried but couldn't reproduce the error. Do you have any example where fast refresh is broken? let useCustom = () => {
let (state, setState) = React.useState(() => "foohhh")
state ++ "foo"
}
let bar = "bar"
@react.component
let default = () => {
let msg = useCustom()
<div>
<Label title="Getting Started" />
{React.string(msg ++ bar)}
</div>
}```
I'm not talking about directly writing the Nextjs page file in res, but just re-exporting the default from res file instead.
eg replace:
```js
import ExamplesRes from "src/Examples.mjs";
// This can be re-exported as is (no Fast-Refresh issues)
export { getServerSideProps } from "src/Examples.mjs";
// Note:
// We need to wrap the make call with
// a Fast-Refresh conform function name,
// (in this case, uppercased first letter)
//
// If you don't do this, your Fast-Refresh will
// not work!
export default function Examples(props) {
return <ExamplesRes {...props}/>;
} with export { getServerSideProps, default } from "src/Examples.mjs"; by adding Thanks! |
According to the Next docs https://nextjs.org/docs/basic-features/fast-refresh#how-it-works, a module is required to only export React components.
Try this (pretty much on every SSRed page): type props;
let default = (props: props) => {
<div/>
} This will export as |
Sorry, I feel like I can't make myself understood 😅.
I actually can make you a PR if you want to test it directly. |
E.g. in or in any scenario where you need static SSG, or SSR, because you probably want to sync the Like here: |
Ok! This was THE thing I missed. For me, even in this case, you would use labeled arguments for props typing. So maybe that the effort could be made on rescript-react to allow passing props type to @react.component, instead of fast-refresh? This can be something useful, event outside next and fast-refresh. |
Yeah there were some ideas on how to make Btw, I found some old thread where we discussed some fast-refresh issues as well: https://forum.rescript-lang.org/t/rescript-nextjs-template-2021-update/829 |
Hi @ryyppy,
Rescript beginner here, I'm digging around nextjs with rescript.
I've seen in all your pages that you can't re-export directly the default, because of fast refresh and the name
$$default
of the components.However, if we use the
@react.component
decorator, the name will not be onlydefault
butMyModule$default
which totaly satitisfy FastRefresh:⇣⇣⇣
My next page is here only:
So why not use the decorator on the default component?
Thanks.
Mathieu.
The text was updated successfully, but these errors were encountered: