deno-docs
deno-docs copied to clipboard
Minor Issues with Deno React Example
Thank you for the Deno React example. It made it possible for me to markedly simplify my project structure!
I've found some issues with it I thought I should mention. So far, I think they're all fairly minor (though one seems major until you fix it 😊).
- It doesn't tell you which of the many templates that mention "react" to pick after running
npm:create-vite-extra
. I went withdeno-react
which appears to have been correct. - It doesn't tell you which language to pick for the purposes of the example. I picked TypeScript because, hey, this is Deno. Later steps, though, seemed to assume JavaScript instead. I'd suggest saying which language to pick, and using that language in the example. (And I'm biased, so I'd suggest using TypeScript😊.)
- After adding the pages to the app, it tells you to start the React app via
deno task start
, but there is nostart
task. I think it means thedev
task. - It still shows the
exact
property on routes, butreact-router-dom
v6 doesn't have that anymore. (Interestingly, the code is using the newerelement
rather than the oldcomponent
property.) (I caught this because, having picked TypeScript, I was editingApp.tsx
instead ofApp.jsx
and TypeScript gave me a helpful error about it.) - (This is the one that looks like a show-stopper at first.) The Deno language service shows errors when you're looking at client-side code, such as:
This is because we don't have aimport React, { useEffect, useState } from "react"; // ^−−−− Relative import path "react" not prefixed // with / or ./ or ../ // deno(import-prefix-missing)
react
entry in our Deno import map, but it can seem like some basic problem resolving modules in the client-side code. Adding this todeno.json
fixes it:"imports": { "react": "npm:react@^18.2", "react-dom": "npm:react-dom@^18.2/client", "react-router-dom": "npm:react-router-dom@^6.4" },
And finally, two suggestions:
- With the above, you end up with your client-side imports in two different places (once in
vite.config.mts
/vite.config.mjs
, and again indeno.json
), It's probably worth noting that duplication, and possibly calling out thevite_plugin_deno_resolve
plugin, which seems to work! (At least for me, so far.) So it may be worth using that plugin in the example (although I'm not sure yet what the ramifications of this issue are and whether that would be a reason not to point to the plugin [yet]). - I wanted to make the
Index.jsx
andDinosaur.jsx
files TypeScript instead of JavaScript. I got there in the end, but ended up having to add"@types/react": "npm:@types/react@^18.2"
to myimports
indeno.json
and then// @deno-types="@types/react"
above the imports from"react"
in each file. Finding out how to do that was a bit painful; it would be good if the example covered that. (And even better if there's a way to enable those types globally rather than having this much boilerplate in each file. I know Fresh manages it somehow...)
Apologies in advance if I've gotten the wrong end of the stick on any of the above.
I'm happy to do a PR for these, though I'd need some hand-holding on it, particularly around the type resolution stuff.
Thanks again for this example!
@kwhinnery - How did I miss that repo? Thanks for moving this to the right place.
Hey @farsightsoftware, sorry for the delay on this! I've actually updated the tutorial completely now, would love to get your feedback on it if you ever have time to take a look! For now im going to close this though.