From 74a1b79ee7c0e29a1eb93237e1b1f21a8e01dc9e Mon Sep 17 00:00:00 2001 From: inmake Date: Fri, 12 Apr 2024 15:09:46 +0500 Subject: [PATCH] upd --- src/stores/useFunctionStore.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/stores/useFunctionStore.ts b/src/stores/useFunctionStore.ts index 212c803..2977e5c 100644 --- a/src/stores/useFunctionStore.ts +++ b/src/stores/useFunctionStore.ts @@ -1,4 +1,6 @@ +/* eslint-disable react-hooks/rules-of-hooks */ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { useNavigate } from "react-router-dom"; import { create } from "zustand"; interface IFunction { @@ -6,17 +8,20 @@ interface IFunction { } interface FunctionState { - functions: IFunction[]; + functions: IFunction; } -const useFunctionStore = create(() => ({ - functions: [ - { - test: (value1: any, value2: any) => { - return value1 + value2; - }, +const navigate = useNavigate(); + +const useFunctionStore = create((set, get) => ({ + functions: { + goToUrl: (url: string) => { + navigate(url); }, - ], + }, + callFunction: (name: string) => { + get().functions[name].apply(get().functions, []); + }, })); export default useFunctionStore;