Skip to Content
文档

用于

用于循环遍历数组并为每个项目渲染一个组件。

SourceStorybook
One
Two
Three

用法

¥Usage

For 组件用于以强类型方式渲染项目列表。它与 .map() 类似。

¥The For component is used to render a list of items in a strongly typed manner. It is similar to the .map().

import { For } from "@chakra-ui/react"
<For each={[]} fallback={...} />

示例

¥Examples

对象

¥Object

以下是使用 For 组件循环遍历对象的示例。

¥Here's an example of using the For component to loop over an object.

Naruto

Powers: Shadow Clone, Rasengan

Sasuke

Powers: Chidori, Sharingan

Sakura

Powers: Healing, Super Strength

回退

¥Fallback

当数组为空或未定义时,使用 fallback 属性渲染备用组件。

¥Use the fallback prop to render a fallback component when the array is empty or undefined.

No items to show

属性

¥Props

PropDefaultType
each
T[] | readonly T[] | undefined

The array to iterate over

fallback
React.ReactNode | undefined

The fallback content to render when the array is empty

Previous

EnvironmentProvider

Next

存在