"Encountered a TypeError while attempting to send a server action to a custom

My custom form component, <ClientForm>, is built using Radix Primitives.

"use client";
import { FC } from "react";
import * as Form from "@radix-ui/react-form";

const ClientForm: FC = (props) => (
  <Form.Root {...props}>
    <Form.Field name="name">
      <Form.Label>Name</Form.Label>
      <Form.Control type="text" required />
    </Form.Field>
    <Form.Submit>OK</Form.Submit>
  </Form.Root>
);

export default ClientForm;

In my page.tsx file, I am trying to render this form component and pass in a server action along with other attributes:

import ClientForm from "@/components/ClientForm";
// server action
import { create } from "@/app/actions";

const Home = () => {
  return (
    <section>
      <h1>Home</h1>
      <ClientForm action={create} />
    </section>
  );
};

However, I encountered a type error:

./src/app/page.tsx:8:19
Type error: Type '{ action: () => void; }' is not assignable to type 'IntrinsicAttributes'.
  Property 'action' does not exist on type 'IntrinsicAttributes'.

   6 |     <section>
   7 |       <h1>Home</h1>
>  8 |       <ClientForm action={create} />
     |                   ^
   9 |     </section>
  10 |   );
  11 | };

I would like to know how I can make the ClientForm component accept the server action and other HTML form attributes seamlessly.

Answer №1

To resolve the type error, implement the following changes:

const InputForm = (attributes: React.ComponentPropsWithoutRef<"form">) => (
...
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can test files be placed under the pages directory in a Next.js project?

Currently, I am in the process of writing integration tests for the API routes within a Next.js application. One question that has arisen is whether it would be problematic to place the index.test.ts file under the /pages directory. My preference leans tow ...

What's the best way to implement an NPM package in a Deno application?

I am curious about integrating the NPM package into my Deno application. Can anyone guide me on how to achieve this? ...

Hey there world! I seem to be stuck at the Loading screen while trying to use Angular

A discrepancy in the browsers log indicates node_modules/angular2/platform/browser.d.ts(78,90): error TS2314: Generic type 'Promise' is missing 2 type arguments. ...

Encountering the issue "SyntaxError: The named export 'useClickAway' is not found" in Next.js while utilizing Storefront UI

After installing storefront ui, I encountered an error whenever I attempted to use any storefrontui block. The error message displayed: "SyntaxError: Named export 'useClickAway' not found. The requested module 'react-use' is a CommonJ ...

Leverage Typescript to convert string literal types to uppercase

type x = 'first' | 'second' I am looking to create a type y that is similar to this: type y = 'FIRST' | 'SECOND' Here is what I attempted: type x = 'first' | 'second' type y = {[key in x]: key[& ...

What steps should be taken to prepare data for transmission to a server in a Next.js environment?

I'm in the process of creating a website that requires authentication. I am using Next (React) and typescript for web development. My objective is to make most pages ServerSideRendered or StaticHTML. However, I encountered an issue right at the begin ...

A method of transferring an accessToken to an Axios interceptor without utilizing Redux

I need to authenticate a Next app by utilizing the current Nodejs backend with a manual JWT strategy. The backend generates an access token, and I am attempting to include accessToken in each request using axios.interceptor where I specify Bearer ${token} ...

Capture individual frames from angular video footage

Trying to extract frames from a video using Angular has been quite challenging for me. While browsing through Stack Overflow, I came across this helpful post here. I attempted to implement the first solution suggested in the post, but unfortunately, I was ...

What is the best way to fully reload an Angular component when the route is changed?

I'm looking for a way to reload or refresh a sidebar component when the route changes. Below is the code I currently have: constructor( private auth: AuthService, private router: Router, private changeDetector: ChangeDetectorRef ) { ...

Using TypeScript to transform types: Array of objects with keys Kn and values Vn to an object with keys Kn and values Vn

I am looking to create a function that can process tuples with a specific structure like so: type Input = [ { key: K1, value: V1 }, { key: K2, value: V2 }, { key: K3, value: V3 }, // ... { key: KN, value: VN } ] The function should then output ...

Tips for organizing an array of objects that contain null properties

Here is an array that I need help with: "data": { "risks": [ { "id": "22", "name": true, "surname": 0.5, "age": 0.75, "heigth" ...

A guide on utilizing a service name as an address to retrieve a dynamic route in next.js

I am facing a challenge where I need to set up a Kubernetes cluster with a NextJS front-end and a service that requires making requests from the front-end to another service within the same cluster using fetch. The issue arises when trying to build the do ...

How to nullify the valueChanges pipe in Angular RxJS until the observable is resolved

A challenge I am facing is piping the valueChanges from a select element to trigger the appropriate API request and displaying a spinner until the response is received. Additionally, I am trying to utilize publish() and refCount() methods so that I can use ...

Here is a method to transform the JSON object into a string as demonstrated below:

Presented below is a JSON object: { "category": "music", "location": { "city": "Braga" }, "date": { "start": { "$gte": "2017-05-01T18:30:00.000Z" }, "end": { "$lt": "2017-05-12T18:30:00.000Z" } } } I am looking t ...

Tips for efficiently passing TypeScript constants to Vue templates without triggering excessive reactivity

I'm curious about the most efficient way to pass a constant value to a template. Currently, I am using the data property in Vue, but I believe that is better suited for state that changes over time as Vue adds event listeners to data properties. The c ...

The Vue CLI project, using Typescript, is facing challenges with building and running Mocha tests

My Vue 2 project, created using Vue CLi, is encountering numerous errors. While it compiles fine for development purposes, running unit tests or building for production results in a cascade of issues. Displayed below are some sample errors, along with sni ...

Steps to transform your Next Js 13 web app into a progressive web app

Currently working on transforming my Next.js 13 app site into a PWA. I've created the manifest.json file and installed next-pwa, along with configuring next.config. The tricky part is figuring out where to place the _document.js file since the folder ...

Developing mongoose models using TypeScript for subdocuments

Exploring the integration of mongoose models with typescript, following a guide available at: https://github.com/Appsilon/styleguide/wiki/mongoose-typescript-models. Unsure how arrays of subdocuments align with this setup. For instance, consider the model ...

Utilizing the arr.push() method to replace an existing value within an array with a new object, rather than simply adding a new

Seeking help to dynamically render a list of components that should expand or shrink based on values being added or removed from an array of custom objects. However, facing an issue where pushing a value into the array only replaces the previous value inst ...

Which option is more beneficial for intercepting API data in Angular 6: interfaces or classes?

My API returns JSON data that is not structured the way I need it, so I have to make changes. { "@odata.context":"xxxxxx", "id":"xxxxxxxx", "businessPhones":[ ], "displayName":"name", "givenName":"pseudo", "jobTitle":null, "ma ...