MCPcopy
hub / github.com/TanStack/router / Editor1Component

Function Editor1Component

examples/react/navigation-blocking/src/main.tsx:142–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140})
141
142function Editor1Component() {
143 const [value, setValue] = React.useState('')
144
145 // Block leaving editor-1 if there is text in the input
146 const { proceed, reset, next, current, status } = useBlocker({
147 shouldBlockFn: () => value !== '',
148 enableBeforeUnload: () => value !== '',
149 withResolver: true,
150 })
151
152 return (
153 <div className="flex flex-col p-2">
154 <h3>Editor 1</h3>
155 <div>
156 <input
157 value={value}
158 onChange={(e) => setValue(e.target.value)}
159 className="border"
160 />
161 </div>
162 <hr className="m-2" />
163 <Link to="/editor-1/editor-2">Go to Editor 2</Link>
164 <Outlet />
165
166 {status === 'blocked' && (
167 <div className="mt-2">
168 <div>Are you sure you want to leave editor 1?</div>
169 <div>
170 You are going from {current.pathname} to {next.pathname}
171 </div>
172 <button
173 className="bg-lime-500 text-white rounded-sm p-1 px-2 mr-2"
174 onClick={proceed}
175 >
176 YES
177 </button>
178 <button
179 className="bg-red-500 text-white rounded-sm p-1 px-2"
180 onClick={reset}
181 >
182 NO
183 </button>
184 </div>
185 )}
186 </div>
187 )
188}
189
190const editor2Route = createRoute({
191 getParentRoute: () => editor1Route,

Callers

nothing calls this directly

Calls 1

useBlockerFunction · 0.90

Tested by

no test coverage detected