import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [{
  "depth": 1,
  "value": "FAQ",
  "children": [{
    "depth": 3,
    "value": "JSX without a virtual DOM? Is this vaporware? I've heard prominent voices say that this isn't possible.",
    "children": []
  }, {
    "depth": 3,
    "value": "How is Solid so performant?",
    "children": []
  }, {
    "depth": 3,
    "value": "Is there React-Compat, or some way to use my React libraries in Solid?",
    "children": []
  }, {
    "depth": 3,
    "value": "Why shouldn't I use map in my template, and what's the difference between <For> and <Index>?",
    "children": []
  }, {
    "depth": 3,
    "value": "Why do I lose reactivity when I destructure props?",
    "children": []
  }, {
    "depth": 3,
    "value": "Why isn't my onChange event handler firing on time?",
    "children": []
  }, {
    "depth": 3,
    "value": "Can you add support for class components? I find the lifecycles are easier to reason about.",
    "children": []
  }, {
    "depth": 3,
    "value": "I really dislike JSX, any chance of a different template language? Oh, I see you have Tagged Template Literals/HyperScript. Maybe I will use those...",
    "children": []
  }, {
    "depth": 3,
    "value": "When do I use a Signal vs Store? Why are these different?",
    "children": []
  }, {
    "depth": 3,
    "value": "Why can I not just assign a value to Solid's Store as I can in Vue, Svelte, or MobX? Where is the 2-way binding?",
    "children": []
  }, {
    "depth": 3,
    "value": "Can I use Solid's reactivity on its own?",
    "children": []
  }, {
    "depth": 3,
    "value": "Does Solid have a Next.js or Material Components like library I can use?",
    "children": []
  }]
}];
function _createMdxContent(props) {
  const _components = Object.assign({
    h1: "h1",
    a: "a",
    h3: "h3",
    p: "p",
    ol: "ol",
    li: "li",
    em: "em",
    code: "code",
    pre: "pre",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsxs(_components.h1, {
      id: "faq",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#faq",
        children: "#"
      }), "FAQ"]
    }), "\n", jsxs(_components.h3, {
      id: "jsx-without-a-virtual-dom-is-this-vaporware-ive-heard-prominent-voices-say-that-this-isnt-possible",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#jsx-without-a-virtual-dom-is-this-vaporware-ive-heard-prominent-voices-say-that-this-isnt-possible",
        children: "#"
      }), "JSX without a virtual DOM? Is this vaporware? I've heard prominent voices say that this isn't possible."]
    }), "\n", jsx(_components.p, {
      children: "It is possible when you don't have React's update model. JSX is a template language like those in Svelte or Vue—just one that is more flexible in certain ways. Inserting arbitrary JavaScript can be challenging at times, but no different than supporting spread operators. So, no: this isn't vaporware, but an approach proven to be one of the most performant."
    }), "\n", jsxs(_components.p, {
      children: ["The real benefit comes in how extensible it is. We have a compiler working for you to give you optimal native DOM updates, but you have all the freedom of a library like React. You can write components using standard techniques like ", jsx(_components.a, {
        href: "https://reactjs.org/docs/render-props.html",
        children: "render props"
      }), " and higher order components along side your reactive \"hooks\". Don't like how Solid's control flow works? Write your own."]
    }), "\n", jsxs(_components.h3, {
      id: "how-is-solid-so-performant",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#how-is-solid-so-performant",
        children: "#"
      }), "How is Solid so performant?"]
    }), "\n", jsx(_components.p, {
      children: "We wish we could point to a single thing, but it really is the combination of several important design decisions:"
    }), "\n", jsxs(_components.ol, {
      children: ["\n", jsx(_components.li, {
        children: "Explicit reactivity, so only the things that should be reactive are tracked."
      }), "\n", jsx(_components.li, {
        children: "Compilation with initial creation in mind. Solid uses heuristics and combines the right expressions to reduce the number of computations, but keep key updates granular and performant."
      }), "\n", jsx(_components.li, {
        children: "Reactive expressions are just functions. This enables \"vanishing components\" with lazy prop evaluation removing unnecessary wrappers and synchronization overhead."
      }), "\n"]
    }), "\n", jsx(_components.p, {
      children: "These are currently unique techniques in a combination that gives Solid an edge over the competition."
    }), "\n", jsxs(_components.h3, {
      id: "is-there-react-compat-or-some-way-to-use-my-react-libraries-in-solid",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#is-there-react-compat-or-some-way-to-use-my-react-libraries-in-solid",
        children: "#"
      }), "Is there React-Compat, or some way to use my React libraries in Solid?"]
    }), "\n", jsx(_components.p, {
      children: "No. And there likely never will be. While the APIs are similar and components often can be moved across with minor edits, the update model is fundamentally different. React Components render over and over so code outside of Hooks works very differently. The closures and hook rules are not only unnecessary in Solid: they can prescribe code that does not work here."
    }), "\n", jsx(_components.p, {
      children: "Vue-Compat, on the other hand, would be doable, although there are no plans to implement it currently."
    }), "\n", jsxs(_components.p, {
      children: ["On the other hand, it is possible to run Solid ", jsx(_components.em, {
        children: "within"
      }), " React. ", jsx(_components.a, {
        href: "https://github.com/solidjs/react-solid-state",
        children: "React Solid State"
      }), " makes the Solid API accessible in React function components. ", jsx(_components.a, {
        href: "https://github.com/Sawtaytoes/reactjs-solidjs-bridge",
        children: "reactjs-solidjs-bridge"
      }), " lets you render React components within Solid components and vice versa, which is useful when gradually porting an app."]
    }), "\n", jsxs(_components.h3, {
      id: "why-shouldnt-i-use-map-in-my-template-and-whats-the-difference-between-for-and-index",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#why-shouldnt-i-use-map-in-my-template-and-whats-the-difference-between-for-and-index",
        children: "#"
      }), "Why shouldn't I use ", jsx(_components.code, {
        children: "map"
      }), " in my template, and what's the difference between ", jsx(_components.code, {
        children: "<For>"
      }), " and ", jsx(_components.code, {
        children: "<Index>"
      }), "?"]
    }), "\n", jsxs(_components.p, {
      children: ["If your array is static, there's nothing wrong with using map. But if you're looping over a signal or reactive property, ", jsx(_components.code, {
        children: "map"
      }), " is inefficient: if the array changes for any reason, ", jsx(_components.em, {
        children: "the entire map"
      }), " will rerun and all of the nodes will be recreated."]
    }), "\n", jsxs(_components.p, {
      children: [jsx(_components.code, {
        children: "<For>"
      }), " and ", jsx(_components.code, {
        children: "<Index>"
      }), " both provide a loop solution that is smarter than this. They couple each rendered node with an element in the array, so when an array element changes, only the corresponding node will rerender."]
    }), "\n", jsxs(_components.p, {
      children: [jsx(_components.code, {
        children: "<Index>"
      }), " will do this ", jsx(_components.em, {
        children: "by index"
      }), ": each node corresponds to an index in the array; ", jsx(_components.code, {
        children: "<For>"
      }), " will do this ", jsx(_components.em, {
        children: "by value"
      }), ": each node corresponds to a piece of data in the array. This is why, in the callback, ", jsx(_components.code, {
        children: "<Index>"
      }), " gives you a signal for the item: the index for each item is considered fixed, but the data at that index can change. On the other hand, ", jsx(_components.code, {
        children: "<For>"
      }), " gives you a signal for the index: the content of the item is considered fixed, but it can move around if elements get moved in the array."]
    }), "\n", jsxs(_components.p, {
      children: ["For example, if two elements in the array are swapped, ", jsx(_components.code, {
        children: "<For>"
      }), " will reposition the two corresponding DOM nodes and update their ", jsx(_components.code, {
        children: "index()"
      }), " signals along the way. ", jsx(_components.code, {
        children: "<Index>"
      }), " won't reposition any DOM nodes, but will update the ", jsx(_components.code, {
        children: "item()"
      }), " signals for the two DOM nodes and cause them to rerender."]
    }), "\n", jsxs(_components.p, {
      children: ["For an in-depth demonstration of the difference, see ", jsx(_components.a, {
        href: "https://www.youtube.com/watch?v=YxroH_MXuhw&t=2164s",
        children: "this segment"
      }), " of Ryan's stream."]
    }), "\n", jsxs(_components.h3, {
      id: "why-do-i-lose-reactivity-when-i-destructure-props",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#why-do-i-lose-reactivity-when-i-destructure-props",
        children: "#"
      }), "Why do I lose reactivity when I destructure props?"]
    }), "\n", jsxs(_components.p, {
      children: ["With a props object, reactivity is enabled by tracking on property access.\nIf you access the property within a ", jsx(_components.em, {
        children: "tracking scope"
      }), "\nlike a JSX expression or an effect, then the JSX expression will rerender or the effect will rerun when that property changes."]
    }), "\n", jsx(_components.p, {
      children: "When you destructure, you access the properties of the object. If this takes place outside of a tracking scope, Solid won't track and rerun\nyour code."
    }), "\n", jsx(_components.p, {
      children: "In this example, the property access happens within the JSX template, so it's\ntracked and the span contents update when the signal changes:"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "function"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "BlueText"
        }), "(", jsx(_components.span, {
          className: "hljs-params",
          children: "props"
        }), ") {\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "return"
        }), " (\n    ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "span"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "style"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "\"color: blue\""
            }), ">"]
          }), "{props.text}", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "span"
            }), ">"]
          })]
        }), "\n  );\n}\n...\n<", jsx(_components.span, {
          className: "hljs-title class_",
          children: "BlueText"
        }), " text={", jsx(_components.span, {
          className: "hljs-title function_",
          children: "mySignal"
        }), "()}/>\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "But neither of these examples will update the span text because the property access happens\noutside of the template:"
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "function"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "BlueText"
        }), "(", jsx(_components.span, {
          className: "hljs-params",
          children: "props"
        }), ") {\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " text = props.", jsx(_components.span, {
          className: "hljs-property",
          children: "text"
        }), ";\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "return"
        }), " (\n    ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "span"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "style"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "\"color: blue\""
            }), ">"]
          }), "{text}", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "span"
            }), ">"]
          })]
        }), "\n  );\n}\n...\n<", jsx(_components.span, {
          className: "hljs-title class_",
          children: "BlueText"
        }), " text={", jsx(_components.span, {
          className: "hljs-title function_",
          children: "mySignal"
        }), "()}/>\n"]
      })
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "function"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "BlueText"
        }), "(", jsx(_components.span, {
          className: "hljs-params",
          children: "{text}"
        }), ") {\n  ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "return"
        }), " (\n    ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "span"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "style"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "\"color: blue\""
            }), ">"]
          }), "{text}", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "span"
            }), ">"]
          })]
        }), "\n  );\n}\n...\n<", jsx(_components.span, {
          className: "hljs-title class_",
          children: "BlueText"
        }), " text={", jsx(_components.span, {
          className: "hljs-title function_",
          children: "mySignal"
        }), "()}/>\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["If you prefer the style of early destructuring, though, there are two different Babel\ntransforms you can use to make (certain styles of) destructuring reactive\nagain: ", jsx(_components.a, {
        href: "https://github.com/orenelbaum/babel-plugin-solid-undestructure",
        children: "babel-plugin-solid-undestructure"
      }), "\nand ", jsx(_components.a, {
        href: "https://github.com/LXSMNSYC/solid-labels",
        children: "Solid Labels'"
      }), " ", jsx(_components.a, {
        href: "https://github.com/LXSMNSYC/solid-labels/blob/main/docs/ctf.md#objects",
        children: "object features"
      }), "."]
    }), "\n", jsxs(_components.h3, {
      id: "why-isnt-my-onchange-event-handler-firing-on-time",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#why-isnt-my-onchange-event-handler-firing-on-time",
        children: "#"
      }), "Why isn't my ", jsx(_components.code, {
        children: "onChange"
      }), " event handler firing on time?"]
    }), "\n", jsxs(_components.p, {
      children: ["In some frameworks, the ", jsx(_components.code, {
        children: "onChange"
      }), " event for inputs is modified so that it fires on every key press. But this isn't how the ", jsx(_components.code, {
        children: "onChange"
      }), " event ", jsx(_components.a, {
        href: "https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onchange",
        children: "works natively"
      }), ": it is meant to reflect a ", jsx(_components.em, {
        children: "committed"
      }), " change to the input and will usually fire when the input loses focus. To handle all changes to the value of an input, use ", jsx(_components.code, {
        children: "onInput"
      }), "."]
    }), "\n", jsxs(_components.h3, {
      id: "can-you-add-support-for-class-components-i-find-the-lifecycles-are-easier-to-reason-about",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#can-you-add-support-for-class-components-i-find-the-lifecycles-are-easier-to-reason-about",
        children: "#"
      }), "Can you add support for class components? I find the lifecycles are easier to reason about."]
    }), "\n", jsx(_components.p, {
      children: "We don't intend to support class components. The lifecycles of components in Solid are tied to the scheduling of the reactive system and are artificial. You could make a class out of it, but effectively all of the non-event handler code would be run in the constructor, including the render function. It's just more syntax for an excuse to make your data less granular."
    }), "\n", jsx(_components.p, {
      children: "Group data and its behaviors together, rather than lifecycles. This is a reactive best practice that has worked for decades."
    }), "\n", jsxs(_components.h3, {
      id: "i-really-dislike-jsx-any-chance-of-a-different-template-language-oh-i-see-you-have-tagged-template-literalshyperscript-maybe-i-will-use-those",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#i-really-dislike-jsx-any-chance-of-a-different-template-language-oh-i-see-you-have-tagged-template-literalshyperscript-maybe-i-will-use-those",
        children: "#"
      }), "I really dislike JSX, any chance of a different template language? Oh, I see you have Tagged Template Literals/HyperScript. Maybe I will use those..."]
    }), "\n", jsx(_components.p, {
      children: "We use JSX the way Svelte uses their templates, to create optimized DOM instructions. The Tagged Template Literal and HyperScript solutions may be really impressive in their own right, but unless you have a real reason like a no-build requirement they are inferior in every way. Larger bundles, slower performance, and the need for manual workaround wrapping values."
    }), "\n", jsx(_components.p, {
      children: "It's good to have options, but Solid's JSX is really the best solution here. A Template DSL would be great as well, albeit more restrictive, but JSX gives us so much for free. Existing Parsers, Syntax Highlighting, Prettier, Code Completion, and last but not least TypeScript."
    }), "\n", jsx(_components.p, {
      children: "Other libraries have been adding support for these features but that has been an enormous effort and is still imperfect and a constant maintenance headache. This is really taking a pragmatic stance."
    }), "\n", jsxs(_components.h3, {
      id: "when-do-i-use-a-signal-vs-store-why-are-these-different",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#when-do-i-use-a-signal-vs-store-why-are-these-different",
        children: "#"
      }), "When do I use a Signal vs Store? Why are these different?"]
    }), "\n", jsx(_components.p, {
      children: "Stores automatically wrap nested values making it ideal for deep data structures, and for things like models. For most other things Signals are lightweight and do the job wonderfully."
    }), "\n", jsxs(_components.p, {
      children: ["As much we would love to wrap these together as a single thing, you can't proxy primitive values, so in this case we use functions. Any reactive expression (including state access) can be wrapped in a function on transport, so this provides a universal API. You can name your signals and state as you choose and it stays minimal. Last thing we'd want to do is force typing ", jsx(_components.code, {
        children: ".get()"
      }), " ", jsx(_components.code, {
        children: ".set()"
      }), " on the end-user or even worse ", jsx(_components.code, {
        children: ".value"
      }), ". At least the former can be aliased for brevity, whereas the latter is just the least terse way to call a function."]
    }), "\n", jsxs(_components.h3, {
      id: "why-can-i-not-just-assign-a-value-to-solids-store-as-i-can-in-vue-svelte-or-mobx-where-is-the-2-way-binding",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#why-can-i-not-just-assign-a-value-to-solids-store-as-i-can-in-vue-svelte-or-mobx-where-is-the-2-way-binding",
        children: "#"
      }), "Why can I not just assign a value to Solid's Store as I can in Vue, Svelte, or MobX? Where is the 2-way binding?"]
    }), "\n", jsx(_components.p, {
      children: "Reactivity is a powerful tool but also a dangerous one. MobX knows this and introduced Strict mode and Actions to limit where/when updates occur. In Solid, which deals with whole Component trees of data, it became apparent that we can learn something from React here. You don't need to be actually immutable as long as you provide the means to have the same contract."
    }), "\n", jsx(_components.p, {
      children: "Being able to pass the ability to update state is arguably even more important than deciding to pass the state. So being able to separate it is important, and only possible if reading is immutable. We also don't need to pay the cost of immutability if we can still granularly update. Luckily there are tons of prior art here between ImmutableJS and Immer. Ironically Solid acts mostly as a reverse Immer with its mutable internals and immutable interface."
    }), "\n", jsxs(_components.h3, {
      id: "can-i-use-solids-reactivity-on-its-own",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#can-i-use-solids-reactivity-on-its-own",
        children: "#"
      }), "Can I use Solid's reactivity on its own?"]
    }), "\n", jsxs(_components.p, {
      children: ["Of course. While we haven't exported a standalone package it is easy to install Solid without the compiler and just use the reactive primitives. One of the benefits of granular reactivity is it is library agnostic. For that matter, almost every reactive library works this way. That is what inspired ", jsx(_components.a, {
        href: "https://github.com/solidjs/solid",
        children: "Solid"
      }), " and its underlying ", jsx(_components.a, {
        href: "https://github.com/ryansolid/dom-expressions",
        children: "DOM Expressions library"
      }), " in the first place to make a renderer purely from the reactive system."]
    }), "\n", jsxs(_components.p, {
      children: ["To list a few to try: ", jsx(_components.a, {
        href: "https://github.com/solidjs/solid",
        children: "Solid"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/mobxjs/mobx",
        children: "MobX"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/knockout/knockout",
        children: "Knockout"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/sveltejs/svelte",
        children: "Svelte"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/adamhaile/S",
        children: "S.js"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/Riim/cellx",
        children: "CellX"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/ds300/derivablejs",
        children: "Derivable"
      }), ", ", jsx(_components.a, {
        href: "https://github.com/luwes/sinuous",
        children: "Sinuous"
      }), ", and even recently ", jsx(_components.a, {
        href: "https://github.com/vuejs/vue",
        children: "Vue"
      }), ". Much more goes into making a reactive library than tagging it onto a renderer like, ", jsx(_components.a, {
        href: "https://github.com/Polymer/lit-html",
        children: "lit-html"
      }), " for example, but it's a good way to get a feel."]
    }), "\n", jsxs(_components.h3, {
      id: "does-solid-have-a-nextjs-or-material-components-like-library-i-can-use",
      children: [jsx(_components.a, {
        className: "header-anchor",
        href: "#does-solid-have-a-nextjs-or-material-components-like-library-i-can-use",
        children: "#"
      }), "Does Solid have a Next.js or Material Components like library I can use?"]
    }), "\n", jsxs(_components.p, {
      children: ["We're working on ", jsx(_components.a, {
        href: "https://github.com/solidjs/solid-start",
        children: "SolidStart"
      }), ", which is our SSR starter solution similar to Next.js or SvelteKit."]
    }), "\n", jsxs(_components.p, {
      children: ["For component libraries, we've got ", jsx(_components.a, {
        href: "https://suid.io/",
        children: "SUID"
      }), " for Material, ", jsx(_components.a, {
        href: "https://hope-ui.com/",
        children: "Hope UI"
      }), " for a Chakra-like solution, ", jsx(_components.a, {
        href: "https://solid-libs.github.io/solid-bootstrap/",
        children: "Solid Bootstrap"
      }), " and plenty more! Check out our ", jsx(_components.a, {
        href: "https://www.solidjs.com/ecosystem",
        children: "rapidly growing ecosystem of libraries and tools"
      }), "."]
    }), "\n", jsxs(_components.p, {
      children: ["If you are interested in building your own ecosystem tool, we are readily available on our ", jsx(_components.a, {
        href: "https://discord.com/invite/solidjs",
        children: "Discord"
      }), ", where you can join existing ecosystem efforts or start your own."]
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=faq-18cccff0.js.map
