@@ -130,7 +130,7 @@ task to run both the React app and the API server.
130
130
In your ` package.json ` file, update the ` scripts ` field to include the
131
131
following:
132
132
133
- ``` jsonc
133
+ ``` jsonc title="package.json"
134
134
{
135
135
" scripts" : {
136
136
" dev" : " deno task dev:api & deno task dev:vite" ,
@@ -143,18 +143,46 @@ following:
143
143
If you run ` deno task dev` now and visit ` localhost: 8000 / api/ dinosaurs` , in your
144
144
browser you should see a JSON response of all of the dinosaurs.
145
145
146
+ ## React support in Deno
147
+
148
+ At this point, your IDE or editor may be showing you warnings about missing
149
+ types in your project. Deno has built-in TypeScript support for React
150
+ applications. To enable this, you'll need to configure your project with the
151
+ appropriate type definitions and DOM libraries. Create or update your
152
+ ` deno .json ` file with the following TypeScript compiler options:
153
+
154
+ ` ` ` jsonc title= " deno.json"
155
+ " compilerOptions" : {
156
+ " types" : [
157
+ " react" ,
158
+ " react-dom" ,
159
+ " @types/react"
160
+ ],
161
+ " lib" : [
162
+ " dom" ,
163
+ " dom.iterable" ,
164
+ " deno.ns"
165
+ ],
166
+ " jsx" : " react-jsx" ,
167
+ " jsxImportSource" : " react"
168
+ }
169
+ ` ` `
170
+
146
171
## Update the entrypoint
147
172
148
173
The entrypoint for the React app is in the ` src/ main .tsx ` file. Ours is going to
149
174
be very basic:
150
175
151
176
` ` ` tsx title= " main.tsx"
152
- import ReactDOM from " react-dom/client " ;
153
- import App from " ./App " ;
177
+ import { StrictMode } from " react" ;
178
+ import { createRoot } from " react-dom/client " ;
154
179
import " ./index.css" ;
180
+ import App from " ./App.tsx" ;
155
181
156
- ReactDOM .createRoot (document .getElementById (" root" ) as HTMLElement ).render (
157
- < App / > ,
182
+ createRoot (document .getElementById (" root" )! ).render (
183
+ < StrictMode>
184
+ < App / >
185
+ < / StrictMode> ,
158
186
);
159
187
` ` `
160
188
@@ -176,8 +204,8 @@ component from `react-router-dom` and define the two routes:
176
204
177
205
` ` ` tsx title= " App.tsx"
178
206
import { BrowserRouter , Route , Routes } from " react-router-dom" ;
179
- import Index from " ./pages/index" ;
180
- import Dinosaur from " ./pages/Dinosaur" ;
207
+ import Index from " ./pages/index.tsx " ;
208
+ import Dinosaur from " ./pages/Dinosaur.tsx " ;
181
209
import " ./App.css" ;
182
210
183
211
function App () {
@@ -285,7 +313,7 @@ it in a paragraph:
285
313
` ` ` tsx title= " Dinosaur.tsx"
286
314
import { useEffect , useState } from " react" ;
287
315
import { Link , useParams } from " react-router-dom" ;
288
- import { Dino } from " ../types" ;
316
+ import { Dino } from " ../types.ts " ;
289
317
290
318
export default function Dinosaur () {
291
319
const { selectedDinosaur } = useParams ();
0 commit comments