Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 1.34 KB

File metadata and controls

43 lines (35 loc) · 1.34 KB
title revalidate

The revalidate function is used to revalidate queries associated with specified query keys. When a query is revalidated, it is executed again, and any references to the associated query data are updated accordingly.

import { For } from "solid-js";
import { query, createAsync, revalidate } from "@solidjs/router";

const getPosts = query(async () => {
	const response = await fetch("https://api.com/posts");
	const data = await response.json();
	return data;
}, "posts");

function Posts() {
	const posts = createAsync(() => getPosts());

	function refetchPosts() {
		revalidate(getPosts.key);
	}

	return (
		<div>
			<button onClick={refetchPosts}>Refetch posts</button>
			<ul>
				<For each={posts()}>{(post) => <li>{post.title}</li>}</For>
			</ul>
		</div>
	);
}

Parameters

  • key: The query key or an array of query keys to be revalidated.
  • force (optional): A boolean that indicates whether to delete the existing cached value of the queries. Note that this cache is solely for de-duplication purposes. Therefore, deleting the cache only affects de-duplication. For more information on how query works, refer to the query documentation. The default value is true.