Skip to content

Why is it called createRouteAction instead of just createAction? #652

@xluk9

Description

@xluk9

Still learning SolidJS and SolidStart. One thing that is confusing me is the name createRouteAction. I understand createRouteAction is executed on the client side.

  • Can't I call that function in a component? What I mean is, can't I call it in non-page component?
  • Can't I call it without a Form?

Suppose i have I global like button in every page, that doesn't need any input params.

import { createRouteAction } from "solid-start/data";
import { createSignal } from "solid-js";

// Global signal, that I should also use in other places
export const [globalLike, setGlobalLike] = createSignal(0);

export function LikeButton() {
  const [liking, like] = createRouteAction(async () => {
    fetch("/increase-like")
    // Should parse response....but for the sake of simplicity
    .then((likes) => setGlobalLike(likes) )
  });

 if ( liking.pending ) return <div>Liking</div>;
 return <div onClick={like()}>Likes are {globalLike()}</div>
}

Would this be wrong? Is this not a best practice?
In this situation, this is not a route action, right? Unless I'm misunderstanding the purpose of createRouteAction

Wouldn't make more sense to just call it createAction ?

While we are at it, is this best practice?

import { createRouteAction } from "solid-start/data";
import { createSignal } from "solid-js";

// Global signal, that I should also use in other places
export const [globalLike, setGlobalLike] = createSignal(0);

// Extract liking logic from the component
export const [liking, like] = createRouteAction(async () => {
    fetch("/increase-like")
    // Should parse response....but for the sake of simplicity
    .then((likes) => setGlobalLike(likes) )
  });

export function LikeButton() {
 if ( liking.pending ) return <div>Liking</div>;
 return <div onClick={like()}>Likes are {globalLike()}</div>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions