Skip to content

Instantly share code, notes, and snippets.

@merthanmerter
merthanmerter / sidebar.tsx
Last active April 28, 2025 07:38
shadcn sidebar cookie state
const SIDEBAR_DEFAULT_OPEN = true; /* (add) */
const SIDEBAR_COOKIE_NAME = "_sidebar";
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
// ...
function SidebarProvider({
defaultOpen, /* :true (remove) */
// ...
}
// ...
@merthanmerter
merthanmerter / __root.tsx
Last active October 27, 2024 17:08
tanstack router - stateful loader data params
export type RootContext = {
store: JotaiStore;
};
export const Route = createRootRouteWithContext<RootContext>()({
component: Root,
});
export default function Root() {
return <Outlet />;
@merthanmerter
merthanmerter / usage.ts
Created October 23, 2024 18:09
tanstack router- useAsyncNavigate
/**
* @see https://github.com/tanstack/router/discussions/2567
*/
await navigate({
to: "/",
invalidate: false,
clearCache: {
before: true,
after: true,
@merthanmerter
merthanmerter / nextjs-use-params-with-type-conversion.ts
Last active October 27, 2024 17:43
Next.js use-params-with-type-conversion hook
export const useParamsWithTypeConversion = <
T extends { [key: string]: (v: string | string[]) => number | boolean | string }
>(
conversions: T
) => {
const params = useParams()
const convertedParams = {} as { [K in keyof T]: ReturnType<T[K]> }
for (const [key, conversion] of Object.entries(conversions)) {
@merthanmerter
merthanmerter / actions.ts
Last active August 9, 2025 11:04
Next Safe Actions & React Hook Form - Reusable form component
// actions.ts
export const addUpdateProject = privateActionClient
.metadata({ actionName: 'addUpdateProject', description: 'Add or update a project.' })
.schema(projectsInsertSchema)
.action(
async ({ parsedInput, ctx }) => {
const { id, ...rest } = parsedInput
const [{ insertId }] = await ctx.db
.insert(projects)