-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to Properly Use Telefunc in Vike for Shared Server and Client Logic? #109
Comments
It isn't clear to me why using Telefunc instead of Vike's data() hook is absolutely necessary for you. Do you mind elaborating why it's a requirement for you? |
Closing, but let's continue the conversation. |
If I use the With my current setup, I export Using the Here’s an overview of my architecture:
This approach decouples my business logic from Vike’s implementation, allowing me to write comprehensive tests for the entire workflow without any specific dependencies on Vike. Vike’s flexibility and customizability make it an excellent choice for my application, while Telefunc provides a seamless way to implement "Server Actions." However, I believe Telefunc should also be callable from the server to maintain a consistent and unified codebase. This would streamline my development process and ensure that my business logic remains centralized and reusable. |
If I use the This duplication of logic increases the complexity of my codebase and the likelihood of inconsistencies between server and client logic. My goal is to maintain a single source of truth for my business logic, ensuring that any changes or updates are automatically reflected across both the server and client. This approach minimizes the risk of errors and simplifies maintenance. In summary, using Effector with Telefunc allows me to centralize my business logic, streamline data fetching, and maintain consistent behavior across server and client environments. This is why I believe Telefunc should be callable from the server as well, to support a more unified and efficient architecture. |
It very much is a goal: #102. I've edited the issue description and added information on how you can achieve this as of today. Let me know if you still have questions. |
Thank you for your responses. I’ve subscribed to the issue and will keep an eye on the updates. For now, I’ve implemented the initial data fetching using the If I can be of any help in writing examples or integrations for Vike + Effector or Telefunc + Effector, please let me know. |
I am using React, TypeScript, Vike, and Telefunc in my project. I need to use the same code for data fetching on both the server and the client. So using +data, is not acceptable for me. Here's my current setup:
Server-side Data Fetching:
Client-side Event Triggering:
Shared Model:
Client-side Rendering:
Server-side Rendering:
Configuration:
The Problem
When I attempt to call the Telefunc function from the server (
+onBeforeRender.ts
), I encounter the error: "Using Telefunc to fetch the initial data of your page is discouraged."However, I need to perform the same operation both on the server and the client without duplicating the code. Essentially, I want to:
/_telefunc
.Questions
renderer/+onRenderClient.tsx
?Additional Context
Any guidance or suggestions to achieve this would be greatly appreciated.
The text was updated successfully, but these errors were encountered: