You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/src/routes/docs/(qwik)/getting-started/index.mdx
+54-42Lines changed: 54 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,36 +22,36 @@ import CodeSandbox from '../../../../components/code-sandbox/index.tsx';
22
22
23
23
# Getting Started Qwikly
24
24
25
-
Qwik is a new kind of framework that is [resumable](../concepts/resumable/index.mdx) (no eager JS execution and no hydration), built for the edge and [familiar to the React developers](/docs/guides/qwik-react/).
25
+
Qwik is a new kind of framework that is [resumable](../concepts/resumable/index.mdx) (no eager JS execution and no hydration), built for the edge and [familiar to React developers](/docs/guides/qwik-react/).
26
26
27
-
If you want to play with it right away, try our in-browser playgrounds:
27
+
To play with it right away, check out our in-browser playgrounds:
The first step is to create a Qwik application with our CLI. The CLI will create a blank starter so that you can quickly familiarize yourself with it. Qwik supports NPM, yarn and pnpm.
42
+
First, create a Qwik application with the Qwik CLI, which generates a blank starter so that you can quickly familiarize yourself with it.
43
43
44
-
Run the Qwik CLI in your shell. Choose the package manager you prefer and run one of the following commands:
44
+
Run the Qwik CLI in your shell. Qwik supports NPM, yarn and pnpm. Choose the package manager you prefer and run one of the following commands:
45
45
46
46
```shell
47
47
npm create qwik@latest
48
48
pnpm create qwik@latest
49
49
yarn create qwik@latest
50
50
```
51
51
52
-
The CLI will guide you through an interactive menu to set the project-name, select one of the starters and asks if you want to install the dependencies. To find out more about the files generated by reading up on the [project structure](/docs/project-structure/).
52
+
The CLI guides you through an interactive menu to set the project-name, select one of the starters and asks if you want to install the dependencies. Find out more about the files generated by referring to the [Project Structure](/docs/project-structure/) documentation.
53
53
54
-
Start the development server
54
+
Start the development server:
55
55
56
56
```shell
57
57
npm start
@@ -61,16 +61,14 @@ yarn start
61
61
62
62
## Qwik Hello World
63
63
64
-
To get you familiar with Qwik we have created a very simple "Hello World" application tutorial that touches on the most important concepts of Qwik. For each part we touch on we will link you to the relevant documentation where you can find out more about the given concept.
65
-
66
-
We will use https://icanhazdadjoke.com as our API to get a random joke. We will create a simple application that will display a random joke and a button to get a new joke.
64
+
The Qwik Hello World tutorial guides you through building a joke app with Qwik while covering the most important Qwik concepts. The app displays a random joke from https://icanhazdadjoke.com and features a button to get a new joke on click.
67
65
68
66
69
67
## 1. Create A Route
70
68
71
-
Everything starts by serving a page at a particular route. So let's build a simple app that serves a random dad joke application on `/joke/` route. Qwikcity (Qwik's meta-framework) uses [directory-based](/docs/routing/) routing. To get started:
69
+
Start by serving a page at a particular route. This basic app serves a random dad joke application on the `/joke/` route. This tutorial relies on Qwikcity, Qwik's meta-framework, which uses [directory-based](/docs/routing/) routing. To get started:
72
70
73
-
1.Create a new `index.tsx` file in the `src/routes/joke/` directory in your project. (You will need to create the `joke` directory first.)
71
+
1.In your project, create a new `joke` directory in `routes` containing an `index.tsx` file.
74
72
2. Each route's `index.tsx` file must have an `export default component$(...)` so that Qwikcity knows what content to serve. Paste the following content to `src/routes/joke/index.tsx`:
> - Your `joke` route default component is surrounded by an existing layout. See [Layout](/docs/layout/) for more details on what layouts are and how to work with them.
91
-
> - For more details about how to author components see the [Component API](/docs/(qwik)/components/overview/index.mdx) section.
89
+
> - For more details about how to author components, see the [Component API](/docs/(qwik)/components/overview/index.mdx) section.
92
90
93
91
## 2. Loading Data
94
92
95
-
A common thing a page does is load data to display to the user. This is performed using[route loaders](/docs/route-loader/).
93
+
To load data to display to the user, use[route loaders](/docs/route-loader/).
96
94
97
95
1. Open `src/routes/joke/index.tsx` and add this code:
Previously we used `routeLoader$` to send data from the server to the client. We use [`routeAction$`](/docs/action/) to post (send) data from the client back to the server.
164
+
Previously, we used `routeLoader$` to send data from the server to the client. To post (send) data from the client back to the server, we use [`routeAction$`](/docs/action/).
165
165
166
-
NOTE: `routeAction$` is the preferred way to send data to the server because it uses the browser native form API which works even if JavaScript is disabled.
166
+
NOTE: `routeAction$` is the preferred way to send data to the server because it uses the browser native form API, which works even if JavaScript is disabled.
167
167
168
168
To declare an action:
169
169
170
-
1.Open`src/routes/joke/index.tsx` and add this code:
3.Navigate to`http://127.0.0.1:5173/` to see the application running.
201
+
3.Now on`http://localhost:5173/joke/`, the buttons display and if you click them, their value logs to the console.
202
202
203
-
What does the above code do?
203
+
Code explanation:
204
204
205
-
-`routeAction$`is used to receive data.
205
+
-`routeAction$`receives the data.
206
206
- The function passed to `routeAction$` is invoked on the server whenever the form is posted.
207
-
- The `routeAction$` returns a use-hook (`useJokeVoteAction`) that can be used in the component post the form data.
207
+
- The `routeAction$` returns a use-hook, `useJokeVoteAction`, that you can use in the component to post the form data.
208
208
-`Form` is a convenience component that wraps the browser's native `<form>` element.
209
209
210
210
Things to note:
211
211
212
-
- For validation see [zod validation](/docs/action/#zod-validation).
212
+
- For validation, see [zod validation](/docs/action/#zod-validation).
213
213
- The `routeAction$` works even if JavaScript is disabled.
214
-
- If JavaScript is enabled the `Form` component will prevent the browser from posting the form and instead post the data using JavaScript and emulate the browser's native form behavior without full refresh.
214
+
- If JavaScript is enabled, the `Form` component will prevent the browser from posting the form and instead post the data using JavaScript and emulate the browser's native form behavior without a full refresh.
215
+
216
+
For reference, the complete code snippet for this section is as follows:
Keeping track of the state and updating UI is core to what applications do. Qwik provides a `useSignal` hook to keep track of the application's state. To learn more see [state management](/docs/components/state/).
257
+
Keeping track of the state and updating the UI is core to what applications do. Qwik provides a `useSignal` hook to keep track of the application's state. To learn more, see [state management](/docs/components/state/).
256
258
257
259
To declare state:
258
260
259
-
1. Declare the component's state using `useSignal()`.
In Qwik, a [task](/docs/components/tasks/#usetask) is work that needs to happen when a state changes. (Similar to an "effect" in other frameworks.) In this example, we will use the task to invoke code on the server.
329
+
In Qwik, a [task](/docs/components/tasks/#usetask) is work that needs to happen when a state changes. (This is similar to an "effect" in other frameworks.) In this example, we use the task to invoke code on the server.
322
330
323
331
1. Create a new task that tracks the `isFavoriteSignal` state:
324
332
```tsx /useTask\$/
@@ -350,10 +358,12 @@ In Qwik, a [task](/docs/components/tasks/#usetask) is work that needs to happen
350
358
351
359
NOTE:
352
360
353
-
-Notice that the body of `useTask$` is executed on both the server and the client (isomorphic).
354
-
- On SSR server prints `FAVORITE (isomorphic) false` and `FAVORITE (server) false`.
361
+
-The body of `useTask$` is executed on both the server and the client (isomorphic).
362
+
- On SSR, the server prints `FAVORITE (isomorphic) false` and `FAVORITE (server) false`.
355
363
- When the user interacts with favorite, the client prints `FAVORITE (isomorphic) true` and the server prints `FAVORITE (server) true`.
356
364
365
+
For reference, the complete code snippet for this section is as follows:
Let's create a production build to see how the application will be delivered to the user and how the above is fixed.
528
+
Let's create a production build that eliminates these issues.
517
529
518
530
Tocreateapreviewbuild:
519
531
@@ -526,10 +538,10 @@ NOTE:
526
538
527
539
## Review
528
540
529
-
Congratulations! You have made it through getting started. This overview is intentionally short to get you familiarized with different parts of Qwik. We recommended that you deep dive into the above concepts to learn more. Here are some key takeaways:
530
-
541
+
Congratulations! You've learned a lot about Qwik!
542
+
For more on just how much you can achieve with Qwik, we recommend reading the dedicated docs on each of the topics touched on in this tutorial:
0 commit comments