Javascript 样式不是';t应用于我用TypeScript创建的React库
我制作了一个React库&在Javascript 样式不是';t应用于我用TypeScript创建的React库,javascript,css,reactjs,typescript,Javascript,Css,Reactjs,Typescript,我制作了一个React库&在examples/文件夹中向该组件添加了样式,但没有应用样式 下面是示例/index.tsx文件: import 'react-app-polyfill/ie11'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { ReactTypical } from '../.'; const App = () => { const hypeText = [
examples/
文件夹中向该组件添加了样式,但没有应用样式
下面是示例/index.tsx
文件:
import 'react-app-polyfill/ie11';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ReactTypical } from '../.';
const App = () => {
const hypeText = ['Creator', 'Entrepreneur', 'Doer', 'Lone Wolf'];
return (
<>
<ReactTypical
style={{
color: 'red',
fontSize: 256,
}}
steps={hypeText.flatMap(hype => [hype, 5000])}
loop={Infinity}
/>
</>
);
};
ReactDOM.render(<App />, document.getElementById('root'));
export type Props = {
steps: Array<any>;
loop: number;
className?: string;
wrapper?: keyof JSX.IntrinsicElements;
} & React.HTMLAttributes<HTMLOrSVGElement>;
我认为React.HTMLAttributes
包含每个React HTML属性,因此style
必须在那里可用
有什么我做错了吗?您的库接受任何
React.HTMLAttributes
,但不使用它们,也不传递它们
你需要这样的东西:
const Typical = ({ steps, loop, className, wrapper: Wrapper = 'p', ...otherProps }: Props) => {
...
return React.createElement(Wrapper, {
...otherProps,
ref: typicalRef,
className: typicalStyles,
});
谢谢你的工作。需要打字吗?我的意思是,
otherProps
的类型是什么?或者我应该这样保留它吗?不。otherProps
是Props
或Props
的子集。Typescript应该自动处理这个问题。