-
Notifications
You must be signed in to change notification settings - Fork 196
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
Server-side validation and module dependency #440
Comments
Hello. I don’t think that there could be any issues with using the package
on the server side.
…On Sat, 24 Feb 2024 at 09:54, Omer Alpi ***@***.***> wrote:
Hello,
I've encountered an issue when using server actions with Next.js and
attempting to validate phone numbers on the server side.
Currently, the documentation/code suggests using:
import { isValidPhoneNumber } from "react-phone-number-input";
However, this import is client-side oriented and might not be suitable for
server-side validations due to its dependency on the
react-phone-number-input package, which is primarily designed for
client-side React applications.
As an alternative, it would be much better if there were a usage like this
for server-side validations within Next.js server actions.
import { isValidPhoneNumber } from 'react-phone-number-input/libphonenumber';
Also, I'm developing the Shadcn Phone Input
<https://github.com/omeralpi/shadcn-phone-input> component using
react-phone-number-input. Thank you.
—
Reply to this email directly, view it on GitHub
<#440>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADUP3ZORO52R6Q2UMLFUCTYVGFC7AVCNFSM6AAAAABDXZDHN2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2TEMJVGEZDCNA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I forgot to include the details. Here you go; Screen.Recording.2024-02-24.at.14.21.04.movError message;
|
Hmm, I see. Well, in that case just import the validation functions from
|
Or, as a workaround, you could do the thing it tells in the error message:
I.e. one could simply mark a parent component *.js file with |
Thank you for your response. The problem starts there. In Server Actions, 'use client' cannot be used. The file from which we import the function, such as 'isValidPhoneNumber', should not contain hooks like useRef. What I mean next is, I believe this issue can be resolved if we import such validation functions separately, for instance, something like 'react-phone-number-input/libphonenumber.' 🙏
The challenge here is to manage the versions and ensure compatibility between these dependencies. 🥹 |
Perhaps not re-exporting the utilities and having to install the dependency would solve similar issues. |
Hello,
I've encountered an issue when using server actions with Next.js and attempting to validate phone numbers on the server side.
Currently, the documentation/code suggests using:
However, this import is client-side oriented and might not be suitable for server-side validations due to its dependency on the react-phone-number-input package, which is primarily designed for client-side React applications.
As an alternative, it would be much better if there were a usage like this for server-side validations within Next.js server actions.
or
The text was updated successfully, but these errors were encountered: