Skip to content
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

After using forwardRef in a JSX component, you encounter an error when using it in a TSX component. #28823

Closed
caihai123 opened this issue Apr 11, 2024 · 1 comment

Comments

@caihai123
Copy link

caihai123 commented Apr 11, 2024

Suppose I have such a JSX component.

// jsx
import { forwardRef } from "react";

const Com= forwardRef(function (props) {
  return <div>{props.text}</div>;
});

export default Com;

And then using it in a TSX file.

// tsx
export default function Page() {
  return (
    <div>
      <Com text="text" />
    </div>
  );
}

will encounter this error.
不能将类型“{ ref: RefObject; text: string; }”分配给类型“IntrinsicAttributes & RefAttributes”。
类型“IntrinsicAttributes & RefAttributes”上不存在属性“text”。

Although I can convert the JSX component to TSX, I would prefer not to.

@eps1lon
Copy link
Collaborator

eps1lon commented Apr 11, 2024

Support requests filed as GitHub issues often go unanswered. We want you to find the answer you're looking for, so we suggest the following alternatives:

Coding Questions
If you have a coding question related to React and React DOM, it might be better suited for Stack Overflow. It's a great place to browse through frequent questions about using React, as well as ask for help with specific questions.

https://stackoverflow.com/questions/tagged/react

Talk to other React developers
There are many online forums which are a great place for discussion about best practices and application architecture as well as the future of React.

https://react.dev/community

@eps1lon eps1lon closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants