-
-
Notifications
You must be signed in to change notification settings - Fork 873
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
Missing props in "table" type definitions #713
Comments
This may be a good add, but it's hard to tell because it is currently framed as an XY Problem. |
This comment has been minimized.
This comment has been minimized.
Yes I can share. I have custom export type TableHeaderCellProps = ThHTMLAttributes<HTMLTableCellElement>;
const HeaderCell = ({ children, ...props }: TableHeaderCellProps) => {
return (
<th {...props}>
{children}
</th>
);
};
export type TableDataCellProps = TdHTMLAttributes<HTMLTableCellElement>;
const DataCell = ({ children, ...props }: TableDataCellProps) => {
return (
<td {...props}>
{children}
</td>
);
}; When I add custom components to import ReactMarkdown from 'react-markdown';
import type { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
type Components = ReactMarkdownOptions['components'];
const Markdown = ({ children }) => {
const initialComponents: Components = {
th: Table.HeaderCell,
td: Table.DataCell,
};
return (
<ReactMarkdown
components={{ ...initialComponents, ...components }}
>
{children}
</ReactMarkdown>
);
}; I receive the following type error:
|
Thanks! I'm not quite following where Reading between the lines a bit, it sounds like you want to reflect react's html element props exactly for the prop type? import React, { DetailedHTMLProps, HTMLAttributes } from "react";
import Markdown from "react-markdown";
const markdownSource = `
# heading
* list
* items
\`\`\`js
function () {}
\`\`\`
`;
const HeaderCell = ({
children,
...props
}: DetailedHTMLProps<
HTMLAttributes<HTMLTableHeaderCellElement>,
HTMLTableHeaderCellElement
>) => {
return <th {...props}>{children}</th>;
};
const DataCell = ({
children,
...props
}: DetailedHTMLProps<
HTMLAttributes<HTMLTableDataCellElement>,
HTMLTableDataCellElement
>) => {
return <td {...props}>{children}</td>;
};
const App = () => (
<Markdown components={{ th: HeaderCell, td: DataCell }}>
{markdownSource}
</Markdown>
);
export default App; runnable example in a sandbox: https://codesandbox.io/s/trusting-hamilton-wnnqfh?file=/src/app.tsx Is that accurate to your end goal? |
Yes exactly. |
Initial checklist
Affected packages and versions
8.0.3
Link to runnable example
No response
Steps to reproduce
Check https://github.com/remarkjs/react-markdown/blob/main/lib/ast-to-react.js#L61 and try to match a
td
orth
component withThHTMLAttributes
orTdHTMLAttributes
fromreact
Expected behavior
as-to-react.js should have
Actual behavior
as-to-react.js has
Runtime
Node v16
Package manager
yarn 1
OS
macOS
Build and bundle tools
Next.js
The text was updated successfully, but these errors were encountered: