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: examples/react/start/README.md
+44-47Lines changed: 44 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
Welcome to your new TanStack app!
1
+
Welcome to your new TanStack app!
2
2
3
3
# Getting Started
4
4
5
5
To run this application:
6
6
7
7
```bash
8
8
pnpm install
9
-
pnpm start
9
+
pnpm start
10
10
```
11
11
12
12
# Building For Production
@@ -29,10 +29,8 @@ pnpm test
29
29
30
30
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
31
31
32
-
33
-
34
-
35
32
## Routing
33
+
36
34
This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.
37
35
38
36
### Adding A Route
@@ -48,7 +46,7 @@ Now that you have two routes you can use a `Link` component to navigate between
48
46
To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
49
47
50
48
```tsx
51
-
import { Link } from"@tanstack/react-router";
49
+
import { Link } from'@tanstack/react-router'
52
50
```
53
51
54
52
Then anywhere in your JSX you can use it like so:
@@ -71,7 +69,7 @@ Here is an example layout that includes a header:
@@ -93,7 +91,6 @@ The `<TanStackRouterDevtools />` component is not required so you can remove it
93
91
94
92
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
95
93
96
-
97
94
## Data Fetching
98
95
99
96
There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
You can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
@@ -221,46 +218,46 @@ pnpm add @tanstack/store
221
218
Now let's create a simple counter in the `src/App.tsx` file as a demonstration.
One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.
245
242
246
243
Let's check this out by doubling the count using derived state.
247
244
248
245
```tsx
249
-
import { useStore } from"@tanstack/react-store";
250
-
import { Store, Derived } from"@tanstack/store";
251
-
import"./App.css";
246
+
import { useStore } from'@tanstack/react-store'
247
+
import { Store, Derived } from'@tanstack/store'
248
+
import'./App.css'
252
249
253
-
const countStore =newStore(0);
250
+
const countStore =newStore(0)
254
251
255
252
const doubledStore =newDerived({
256
253
fn: () =>countStore.state*2,
257
254
deps: [countStore],
258
-
});
259
-
doubledStore.mount();
255
+
})
256
+
doubledStore.mount()
260
257
261
258
function App() {
262
-
const count =useStore(countStore);
263
-
const doubledCount =useStore(doubledStore);
259
+
const count =useStore(countStore)
260
+
const doubledCount =useStore(doubledStore)
264
261
265
262
return (
266
263
<div>
@@ -269,10 +266,10 @@ function App() {
269
266
</button>
270
267
<div>Doubled - {doubledCount}</div>
271
268
</div>
272
-
);
269
+
)
273
270
}
274
271
275
-
exportdefaultApp;
272
+
exportdefaultApp
276
273
```
277
274
278
275
We use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount` method that will start the derived store updating.
0 commit comments