小编ana*_*spi的帖子

切换大小写以在 JSX 上渲染多个组件

我有条件地渲染一些组件,但我想知道是否有更有效的方法(例如,使用 switch case):

     export const Culture = () => {
      const { query } = useRouter();
      const currentSection = query.section || "";
      return (
        <div className="content">
          <Navigation
            className={currentSection !== "" ? "sub_nav" : "sub_nav active_menu"}
            category="culture"
          />
          {currentSection === "" && <CultureCulture category="cultureCulture" />}
          {currentSection === "elephant" && (
            <CultureCulture category="cultureElephant" />
          )}
          {(currentSection === "espace-musee" ||
            currentSection === "quebecor-gallery") && (
            <CultureCulture category="cultureGallery" />
          )}
          {currentSection === "culture-d-ici" && (
            <CultureCulture category="cultureIci" />
          )}
          {(currentSection === "bilan-culturel" ||
            currentSection …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

next.js ×1

reactjs ×1