Skip to content

Commit 3eb26ab

Browse files
docs: update copy in getting started (#3741)
1 parent ceeb792 commit 3eb26ab

1 file changed

Lines changed: 54 additions & 42 deletions

File tree

  • packages/docs/src/routes/docs/(qwik)/getting-started

packages/docs/src/routes/docs/(qwik)/getting-started/index.mdx

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,36 @@ import CodeSandbox from '../../../../components/code-sandbox/index.tsx';
2222

2323
# Getting Started Qwikly
2424

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/).
2626

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:
2828

2929
- [StackBlitz Qwik](https://qwik.new) (Full Qwik + Qwikcity integration)
3030
- [Examples playground](/examples/reactivity/counter/) (Qwik only (no routing))
3131

3232
## Prerequisites
3333

34-
If you want to get started with Qwik locally, you will need the following:
34+
To get started with Qwik locally, you need the following:
3535

3636
- [Node.js v16.8](https://nodejs.org/en/download/) or higher
3737
- Your favorite IDE ([vscode](https://code.visualstudio.com/) recommended)
38-
- Optionally you may want to read [think qwik](../think-qwik/index.mdx)
38+
- Optionally, read [think qwik](../think-qwik/index.mdx)
3939

4040
## Create an app using the CLI
4141

42-
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.
4343

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:
4545

4646
```shell
4747
npm create qwik@latest
4848
pnpm create qwik@latest
4949
yarn create qwik@latest
5050
```
5151

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.
5353

54-
Start the development server
54+
Start the development server:
5555

5656
```shell
5757
npm start
@@ -61,16 +61,14 @@ yarn start
6161

6262
## Qwik Hello World
6363

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.
6765

6866

6967
## 1. Create A Route
7068

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:
7270

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.
7472
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`:
7573

7674
<CodeSandbox src="/src/routes/demo/getting-started/01-route/index.tsx" style={{ height: '6em' }}>
@@ -88,11 +86,11 @@ export default component$(() => {
8886
> NOTE:
8987
>
9088
> - 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.
9290
9391
## 2. Loading Data
9492

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/).
9694

9795
1. Open `src/routes/joke/index.tsx` and add this code:
9896

@@ -120,18 +118,20 @@ export default component$(() => {
120118
});
121119
```
122120

123-
3. Navigate to `http://127.0.0.1:5173/` to see the application running.
121+
3. Now on `http://localhost:5173/joke/`, the browser displays a random joke.
124122

125-
What does the above code do?
123+
Code explanation:
126124

127125
- The function passed to `routeLoader$` is invoked on the server eagerly before any component is rendered and is responsible for loading data.
128-
- The `routeLoader$` returns a use-hook (`useDadJoke`) that can be used in the component to retrieve the server data.
126+
- The `routeLoader$` returns a use-hook, `useDadJoke()`, that can be used in the component to retrieve the server data.
129127

130128
> **NOTE**
131129
>
132130
> - The `routeLoader$` is invoked eagerly on the server before any component is rendered, even if its use-hook is not invoked in any component.
133131
> - The `routeLoader$` return type is inferred in the component without the need for any additional type information.
134132
133+
For reference, the complete code snippet for this section is as follows:
134+
135135
<CodeSandbox src="/src/routes/demo/getting-started/02-loading-data/index.tsx" style={{ height: '6em' }}>
136136
```tsx /routeLoader$/ /useDadJoke/
137137
import { component$ } from '@builder.io/qwik';
@@ -159,15 +159,15 @@ export default component$(() => {
159159
```
160160
</CodeSandbox>
161161

162-
## 3. Posting Data to Server
162+
## 3. Posting Data to the Server
163163

164-
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/) .
165165

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.
167167

168168
To declare an action:
169169

170-
1. Open `src/routes/joke/index.tsx` and add this code:
170+
1. In `src/routes/joke/index.tsx`, add this code:
171171

172172

173173
```tsx /routeAction\$/
@@ -179,7 +179,7 @@ export const useJokeVoteAction = routeAction$((props) => {
179179
});
180180
```
181181

182-
2. Update the `export default` component to use the `useJokeVoteAction` hook. This is done by adding the `<Form>`.
182+
2. Update the `export default` component to use the `useJokeVoteAction` hook with `<Form>`.
183183

184184
```tsx {3,7-11} /favoriteJokeAction/
185185
export default component$(() => {
@@ -198,20 +198,22 @@ export default component$(() => {
198198
});
199199
```
200200

201-
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.
202202

203-
What does the above code do?
203+
Code explanation:
204204

205-
- `routeAction$` is used to receive data.
205+
- `routeAction$` receives the data.
206206
- 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.
208208
- `Form` is a convenience component that wraps the browser's native `<form>` element.
209209

210210
Things to note:
211211

212-
- For validation see [zod validation](/docs/action/#zod-validation).
212+
- For validation, see [zod validation](/docs/action/#zod-validation).
213213
- 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:
215217

216218
<CodeSandbox src="/src/routes/demo/getting-started/03-posting-data/index.tsx" style={{ height: '8em' }}>
217219
```tsx {21,25-29} /favoriteJokeAction/
@@ -252,15 +254,19 @@ export default component$(() => {
252254

253255
## 4. Modifying State
254256

255-
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/).
256258

257259
To declare state:
258260

259-
1. Declare the component's state using `useSignal()`.
261+
1. Import `useSignal` from `qwik`.
262+
```tsx /useSignal/
263+
import { component$, useSignal } from "@builder.io/qwik";
264+
```
265+
2. Declare the component's state using `useSignal()`.
260266
```tsx /useSignal/
261267
const isFavoriteSignal = useSignal(false);
262268
```
263-
2. Add a button to the component that will modify the state.
269+
3. After the closing `Form` tag, add a button to the component to modify the state.
264270
```tsx /isFavoriteSignal/
265271
<button
266272
onClick$={() => {
@@ -270,7 +276,9 @@ To declare state:
270276
</button>
271277
```
272278

273-
NOTE: Clicking on the button will update the state and the UI will be updated.
279+
NOTE: Clicking on the button updates the state, which in turn updates the UI.
280+
281+
For reference, the complete code snippet for this section is as follows:
274282

275283
<CodeSandbox maxHeight={500} src="/src/routes/demo/getting-started/04-state/index.tsx" style={{ height: '10em' }}>
276284
```tsx /isFavoriteSignal/
@@ -318,7 +326,7 @@ export default component$(() => {
318326

319327
## 5. Tasks and Invoking Server Code
320328

321-
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.
322330

323331
1. Create a new task that tracks the `isFavoriteSignal` state:
324332
```tsx /useTask\$/
@@ -350,10 +358,12 @@ In Qwik, a [task](/docs/components/tasks/#usetask) is work that needs to happen
350358

351359
NOTE:
352360

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`.
355363
- When the user interacts with favorite, the client prints `FAVORITE (isomorphic) true` and the server prints `FAVORITE (server) true`.
356364

365+
For reference, the complete code snippet for this section is as follows:
366+
357367
<CodeSandbox maxHeight={500} src="/src/routes/demo/getting-started/05-tasks/index.tsx" style={{ height: '10em' }}>
358368
```tsx {28-34}
359369
import { component$, useSignal, useTask$ } from '@builder.io/qwik';
@@ -436,12 +446,14 @@ To add styles:
436446
useStylesScoped$(STYLES);
437447
```
438448

439-
NOTE:
449+
Code explanation:
440450

441451
- The `?inline` query parameter tells Vite to inline the styles into the component.
442452
- The `useStylesScoped$` call tells Qwik to associate the styles with the component only (scoping).
443453
- Styles are only loaded if they are not already inlined as part of SSR and only for the first component.
444454

455+
For reference, the complete code snippet for this section is as follows:
456+
445457
<CodeSandbox maxHeight={500} src="/src/routes/demo/getting-started/06-styling/index.tsx" style={{ height: '10em' }}>
446458
```tsx /useStylesScoped\$/
447459
import {
@@ -506,14 +518,14 @@ export default component$(() => {
506518

507519
## 7. Preview
508520

509-
We build a very simple application that gave you an overview of key Qwik concepts and API. The application is running in dev mode, which uses hot-module-reloading (HMR) to continuously update the application while changing the code.
521+
We built a minimal application that gave you an overview of key Qwik concepts and API. The application is running in dev mode, which uses hot-module-reloading (HMR) to continuously update the application while changing the code.
510522

511523
While in dev mode:
512524

513525
- Each file is loaded individually, which may cause waterfalls in the network tab.
514526
- There is no speculative loading of bundles, so there may be a delay on the first interaction.
515527

516-
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.
517529

518530
To create a preview build:
519531

@@ -526,10 +538,10 @@ NOTE:
526538

527539
## Review
528540

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:
531543

532-
- [Project structure](/docs/(qwikcity)/project-structure/index.mdx)
544+
- [Project structure](/docs/(qwikcity)/project-structure/index.mdx):
533545
- [Directory-based](/docs/(qwikcity)/routing/index.mdx) routing
534546
- [Component](/docs/(qwik)/components/overview/index.mdx)
535547
- [Route loaders](/docs/(qwikcity)/route-loader/index.mdx)

0 commit comments

Comments
 (0)