fresh icon indicating copy to clipboard operation
fresh copied to clipboard

[QUESTION] Components vs Islands

Open nikableh opened this issue 4 years ago • 3 comments

  1. Should I create a separate /components folder for my .tsx components if they are not strictly interactive like islands supposed to be? Or do I need to put such components inside /island directory no matter if they are interactive or not?
  2. Is it a requirement for an island to be interactive?
  3. What is considered interactive in terms of islands?
  4. In what way are islands (I assume that islands are considered to be all the .tsx files in /islands directory) treated differently from just regular .tsx components? If I do this...
/** @jsx h */
import { h } from "preact";
import MyComponent from "../some-random-directory/MyComponent.tsx";

export default function Home() {
  return (
    <MyComponent/>
  );
}

...how exactly it is being treated differently from this...

/** @jsx h */
import { h } from "preact";
import MyComponent from "../islands/MyComponent.tsx";

export default function Home() {
  return (
    <MyComponent/>
  );
}

I did read about island architecture and somewhat understood it, so my questions are more about best practices (or at least how people think it should be done) of creating an app with Fresh.

nikableh avatar Jul 05 '22 09:07 nikableh

It seems that what I'm asking is similar to what is discussed in https://github.com/denoland/fresh/discussions/326#discussioncomment-3058069 and proposed in https://github.com/denoland/fresh/issues/350

nikableh avatar Jul 05 '22 09:07 nikableh

I suppose I should have posted this question in the discussion tab. I'm sorry.

nikableh avatar Jul 05 '22 09:07 nikableh

Components are static, islands are dynamic. They should be split across folders as such. You should never have static islands.

Interactive means you need to do some logic client side, for example onclick, useEffect, useState or similar.

lucacasonato avatar Jul 06 '22 10:07 lucacasonato