1

I am trying to start a side project with SolidStart and I noticed some functions are named the same way a React hook would be named (eg: useLocation, useParams, etc...)

I am confused by this somewhat since I see many functions that are the analogs of standard react hooks like createSignal, createEffect, createQuery, etc...

Looking at the documentation for both Solid Start and Solid Js I could not find any particular nomenclature for such functions, though I've seen those that start with create being referred to as factories.

React has special rules for hooks, which are functions that start with "use". I'm wondering if there is are any special rules / functionality for functions starting with "create" and "use" in SolidJs and Solid Start.

kaan_a
  • 3,503
  • 1
  • 28
  • 52
  • 1
    "*React has special rules for functions that start with "use"*" - no, it has special rules for hooks (including custom hooks, which are defined as functions calling native hooks), **and** it has a naming convention to help identifying such hook functions. – Bergi Jul 01 '23 at 13:54

1 Answers1

2

Solid has no hooks and there are no implicit rules attached to variable names. Although there are no set rules or a style guide on how to choose names, generally function names start with create if they create a signal or an effect or an internal resource. Names with use are usually preferred if the function operates over an existing resource.

You can find clues on the topic on Ryan Carniato's Youtube streams and in some issues and discussions:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
snnsnn
  • 10,486
  • 4
  • 39
  • 44
  • This is a great answer. I enjoyed the information you provided about array destructuring. I never thought about how it would affect bundle size. That being said it is entirely irrelevant to the question and specific to createSignal and createResource. I also think that the assertion that React and Solid have nothing in common is overstated. Both libraries have the same purpose and naturally use similar concepts and usage, though the implementation is very different, obviously. I have taken the liberty to edit your answer to the most relevant parts. I hope this causes no offence. – kaan_a Jul 02 '23 at 20:11
  • > "I also think that the assertion that React and Solid have nothing in common is overstated" From technical perspective, yes, they don't have anything in common other than having similar function names and array descructuring. Purpose is too abstract to be a measure of comparison. The part you removed was not irrelevant, it was the meat of the answer, it was the why part, why is the similarity, why you had the question in the first place. – snnsnn Jul 02 '23 at 20:28
  • I assure you that I would have had the same question if either React's `useState` or Solid's `createSignal` returned an object instead of an array. These two funciton names aren't even remotely similar, however they do serve the same purpose: adding a reactive state to a component. This combined with the fact that Solid, much like React exposes its most commonly used features using the same verb is what causes the confusion for developers comming over from React. – kaan_a Jul 02 '23 at 22:28
  • React is not reactive. You are missing some of the core principles of the tech we are discussing. Also looking at the problem from very narrow perspective. And have big assumptions based on so called "purposes". Purpose means nothing. What they do, and how they do the things they are doing is our concern. As you might see I was trying to address the problems like why people think Solid looks or feels like React, it was for you as well as others. Turns out we had different purpose :) – snnsnn Jul 03 '23 at 05:34
  • "React is not reactive" Really? It's literally called "React". It's hardly pro-active or unreactive like a rock. The fact that reacting to a change in state requires re-rendering entire component trees does not make something unreactive just inefficient. I never asked why people think Solid feels like React. I asked what if any rules are attached to functions whose names start with use or create. If you want to answer why people think Solid feels like React feel free to make your own question and answer, or a blog post or whatever. It's very much off topic. – kaan_a Jul 03 '23 at 12:21
  • I think you are confusing the more specific term reactive primitives with more general reactivity. React is reactive on the component level, Solid JS has reactive primitives. – kaan_a Jul 03 '23 at 12:25