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
+46-43Lines changed: 46 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
Welcome to your new TanStack app!
1
+
Welcome to your new TanStack app!
2
2
3
3
# Getting Started
4
4
@@ -29,8 +29,10 @@ pnpm test
29
29
30
30
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
31
31
32
-
## Routing
33
32
33
+
34
+
35
+
## Routing
34
36
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`.
35
37
36
38
### Adding A Route
@@ -46,7 +48,7 @@ Now that you have two routes you can use a `Link` component to navigate between
46
48
To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
47
49
48
50
```tsx
49
-
import { Link } from'@tanstack/react-router'
51
+
import { Link } from"@tanstack/react-router";
50
52
```
51
53
52
54
Then anywhere in your JSX you can use it like so:
@@ -69,7 +71,7 @@ Here is an example layout that includes a header:
@@ -91,6 +93,7 @@ The `<TanStackRouterDevtools />` component is not required so you can remove it
91
93
92
94
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
93
95
96
+
94
97
## Data Fetching
95
98
96
99
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).
@@ -218,46 +221,46 @@ pnpm add @tanstack/store
218
221
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.
242
245
243
246
Let's check this out by doubling the count using derived state.
244
247
245
248
```tsx
246
-
import { useStore } from'@tanstack/react-store'
247
-
import { Store, Derived } from'@tanstack/store'
248
-
import'./App.css'
249
+
import { useStore } from"@tanstack/react-store";
250
+
import { Store, Derived } from"@tanstack/store";
251
+
import"./App.css";
249
252
250
-
const countStore =newStore(0)
253
+
const countStore =newStore(0);
251
254
252
255
const doubledStore =newDerived({
253
256
fn: () =>countStore.state*2,
254
257
deps: [countStore],
255
-
})
256
-
doubledStore.mount()
258
+
});
259
+
doubledStore.mount();
257
260
258
261
function App() {
259
-
const count =useStore(countStore)
260
-
const doubledCount =useStore(doubledStore)
262
+
const count =useStore(countStore);
263
+
const doubledCount =useStore(doubledStore);
261
264
262
265
return (
263
266
<div>
@@ -266,10 +269,10 @@ function App() {
266
269
</button>
267
270
<div>Doubled - {doubledCount}</div>
268
271
</div>
269
-
)
272
+
);
270
273
}
271
274
272
-
exportdefaultApp
275
+
exportdefaultApp;
273
276
```
274
277
275
278
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