Skip to content

Commit 2fb94d1

Browse files
committed
docs(start): add imports and no-op explanation
1 parent 3555266 commit 2fb94d1

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

docs/start/framework/react/environment-functions.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ Start provide three core environment functions:
1919

2020
Use `createIsomorphicFn()` to define functions that behave differently depending on whether they are called on the client or the server. This is useful for safely sharing logic across environments while delegating environment-specific behavior to appropriate handlers.
2121

22-
> [!WARNING]
23-
> Unimplemented function results in a no-op function.
24-
2522
### Complete Implementation
2623

2724
```tsx
25+
import { createIsomorphicFn } from '@tanstack/react-start';
26+
2827
const getEnv = createIsomorphicFn()
2928
.server(() => 'server')
3029
.client(() => 'client')
@@ -39,6 +38,8 @@ const env = getEnv()
3938
Here is an example of `createIsomorphicFn()` with only server implementation:
4039

4140
```tsx
41+
import { createIsomorphicFn } from '@tanstack/react-start';
42+
4243
const serverImplementationOnly = createIsomorphicFn().server(() => 'server')
4344

4445
const server = serverImplementationOnly()
@@ -51,6 +52,8 @@ const server = serverImplementationOnly()
5152
Here is an example of `createIsomorphicFn()` with only client implementation:
5253

5354
```tsx
55+
import { createIsomorphicFn } from '@tanstack/react-start';
56+
5457
const clientImplementationOnly = createIsomorphicFn().client(() => 'client')
5558

5659
const client = clientImplementationOnly()
@@ -63,12 +66,23 @@ const client = clientImplementationOnly()
6366
Here is an example of `createIsomorphicFn()` without any environment specific implementation:
6467

6568
```tsx
69+
import { createIsomorphicFn } from '@tanstack/react-start';
70+
6671
const noImplementation = createIsomorphicFn()
6772

6873
const noop = noImplementation()
6974
// ℹ️ On both **client** and **server**, it is no-op (returns `undefined`)
7075
```
7176

77+
#### What is a no-op?
78+
79+
A no-op (short for "no operation") is a function that does nothing when executed - it simply returns `undefined` without performing any operations.
80+
81+
```tsx
82+
// basic no-op implementation
83+
function noop() {}
84+
```
85+
7286
---
7387

7488
## `env`Only Functions
@@ -78,6 +92,8 @@ The `serverOnly` and `clientOnly` helpers enforce strict environment-bound execu
7892
### `serverOnly`
7993

8094
```tsx
95+
import { serverOnly } from '@tanstack/react-start';
96+
8197
const foo = serverOnly(() => 'bar')
8298

8399
foo() // ✅ On server: returns "bar"
@@ -87,6 +103,8 @@ foo() // ✅ On server: returns "bar"
87103
### `clientOnly`
88104

89105
```tsx
106+
import { clientOnly } from '@tanstack/react-start';
107+
90108
const foo = clientOnly(() => 'bar')
91109

92110
foo() // ✅ On client: returns "bar"
@@ -100,6 +118,7 @@ foo() // ✅ On client: returns "bar"
100118

101119
Environment functions are tree-shaken based on the environment for each bundle produced.
102120

103-
On the server, functions created using `createIsomorphicFn()` are tree-shaken. So, all code used inside `.client()` are not included in server bundle, and vice-versa.
121+
Functions created using `createIsomorphicFn()` are tree-shaken. All codes inside `.client()` are not included in server bundle, and vice-versa.
104122

105123
On the server, implementation of `clientOnly` functions are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions on the client.
124+

docs/start/framework/react/server-functions.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ response?: 'data' | 'full' | 'raw'
9797
- From client-side code
9898
- From other server functions
9999

100-
> [!WARNING]
101-
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both. See [Environment Functions](../environment-functions.md) for more.
102-
103100
## Accepting Parameters
104101

105102
Server functions accept a single parameter, which can be a variety of types:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
ref: docs/start/framework/react/environment-functions.md
3+
replace: { 'react': 'solid' }
34
---

0 commit comments

Comments
 (0)