Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solid syntax #9

Closed
jer3m01 opened this issue May 8, 2024 · 1 comment
Closed

Solid syntax #9

jer3m01 opened this issue May 8, 2024 · 1 comment

Comments

@jer3m01
Copy link
Contributor

jer3m01 commented May 8, 2024

Here's a few tricks to make component syntax shorter:

<Show when={selectedGame().favourite}>
  <div className="relative">
    <div className="!w-max"> {translateText("favourite")}</div>
    <div className="absolute blur-[5px] opacity-70 -z-10 inset-0 !w-max">
      {translateText("favourite")}
    </div>
  </div>
</Show>
<Show when={!selectedGame().favourite}>
  <div className="!w-max"> {translateText("favourite")}</div>
</Show>

// is equal to

<Show when={selectedGame().favourite} fallback={<div className="!w-max"> {translateText("favourite")}</div>}>
  <div className="relative">
    <div className="!w-max"> {translateText("favourite")}</div>
    <div className="absolute blur-[5px] opacity-70 -z-10 inset-0 !w-max">
      {translateText("favourite")}
    </div>
  </div>
</Show>

https://docs.solidjs.com/reference/components/show

<Show when={editedLocatedGame() === undefined}>
  ...
</Show>
<Show when={editedLocatedGame() === null}>
  ...
</Show>
<Show when={editedLocatedGame()}>
  ...
</Show>

// can be replaced by

<Switch>
  <Match when={editedLocatedGame() === undefined}>
    ...
  </Match>
  <Match when={editedLocatedGame() === null}>
    ...
  </Match>
  <Match when={editedLocatedGame()}>
    ...
  </Match>
</Switch>

// or

<Switch fallback={... /* same as `when={editedLocatedGame()}` */}>
  <Match when={editedLocatedGame() === undefined}>
    ...
  </Match>
  <Match when={editedLocatedGame() === null}>
    ...
  </Match>
</Switch>

https://docs.solidjs.com/reference/components/switch-and-match

Also in general I'd recommend making smaller components (splitting into multiple functions or files).
And either placing all svg icons in a separate file (example) or an icon library (like solid-icons).

@adithyasource
Copy link
Owner

Thank you for the suggestion! I've implemented proper switch/match statements and fallbacks in e940de7. Splitting icons into their own separate file was done in e6cceee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants