Created
December 19, 2025 00:37
-
-
Save mohadib/3172187c9e47d9e232c0bfdf893d6f8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {createFileRoute, useNavigate, useSearch} from '@tanstack/react-router' | |
| import {useState, Activity} from 'react' | |
| export const Route = createFileRoute('/test')({ | |
| component: RouteComponent, | |
| }) | |
| function RouteComponent() { | |
| const view = useSearch({ | |
| strict: false, | |
| select: state => state.view | |
| }) | |
| const nav = useNavigate() | |
| const showMap = () => { | |
| nav({ | |
| search: {view:'map'}, | |
| }) | |
| } | |
| const showList = () => { | |
| nav({ | |
| search: {view:'list'}, | |
| }) | |
| } | |
| const [count, setCount] = useState(1) | |
| return ( | |
| <div> | |
| <Activity mode={view === 'list' ? 'visible' : 'hidden'}> | |
| <div>Showing list</div> | |
| <div>{count}</div> | |
| <button onClick={() => setCount(count + 1)}>click</button> | |
| <button onClick={showMap}>switch</button> | |
| </Activity> | |
| <Activity mode={view === 'map' ? 'visible' : 'hidden'}> | |
| <div>Showing map</div> | |
| <button onClick={() => setCount(count + 1)}>click</button> | |
| <button onClick={showList}>switch</button> | |
| </Activity> | |
| </div> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment