我正在使用react-router v6,是否可以在不使用Outlet组件的情况下使用嵌套路由?
例如:我有一个用户页面和 onClick 用户组件,它应该导航到特定的用户页面,
当前尝试:
<Routes>
<Route path="/" element={<Home />} />
<Route path="/users" element={<Users />} />
<Route path=":id" element={<UserPage/>} />
</Routes>
Run Code Online (Sandbox Code Playgroud)
然后单击特定用户:
const gotoUserPage = () => {
navigate('1')
}
Run Code Online (Sandbox Code Playgroud)
gotoUserPage 将 URL 从“/users”更改为“/users/1”,但 userPage 组件不会呈现。
我正在使用react-router V6并尝试测试useOutletContext的新功能。我的测试库是testing-library/react,我不确定如何在测试中传递上下文数据。
在 TSX 组件中,我使用 React-router 的钩子获取数据:
const { data } = useOutletContext<IContext>()
Run Code Online (Sandbox Code Playgroud)
我需要类似的东西:
test("render outlet context data view", async () => {
const { getByTestId } = render(
<MockedProvider mocks={[mockData]} context={myContextData}>
<ContextDataView />
</MockedProvider>
)
Run Code Online (Sandbox Code Playgroud)
MockedProvider 标签来自@apollo/client/testing
context={myContextData} 部分是我需要的
我正在尝试使用反应变量:
我的缓存文件:
import { makeVar } from "@apollo/client"
export const colorVar = makeVar('red')
Run Code Online (Sandbox Code Playgroud)
文件 A(更新值):
import { colorVar } from "cache"
colorVar('green')
Run Code Online (Sandbox Code Playgroud)
文件 B(读取值并应在文件 A 中更新值后重新渲染):
import { colorVar } from "cache"
console.log(colorVar())
Run Code Online (Sandbox Code Playgroud)
文件 A 中的更新操作不会触发文件 B 的重新渲染
我正在尝试构建一个简单的组件,它将进行一次 API 调用,并在 2 秒后重定向到另一个页面。为此,我尝试使用react-router-dom中的重定向组件,但导入失败
import { Redirect } from "react-router-dom"
Run Code Online (Sandbox Code Playgroud)
我收到错误:“react-router-dom 没有导出成员‘重定向’。”
版本“react-router-dom”:“^6.0.0-beta.0”,
我使用 dayJS 作为我的日期时间库,并希望呈现所有时区的列表。
我尝试使用 Intl 对象:
Intl.supportedValuesOf("timeZone")
但出现打字稿错误:
TS2339: Property 'supportedValuesOf' does not exist on type 'typeof Intl'.
我可以获取值,但我想避免使用 @ts-ignore 表示法
如何为 Intl 对象添加更新的类型?