react-pose
-
@reach/router
示例到TypeScript,但它不起作用。
以下是相关的打字
反应式
:
import { ComponentType, HTMLProps } from 'react';
import { PoseElementProps } from './components/PoseElement/types';
import { DomPopmotionConfig } from 'popmotion-pose';
declare type DomPopmotionConfigFactory<T> = (props: PoseElementProps & T) => DomPopmotionConfig;
export declare type ComponentFactory<T> = (poseConfig?: DomPopmotionConfig | DomPopmotionConfigFactory<T>) => ComponentType<PoseElementProps & T>;
export declare type Posed = {
<T>(component: ComponentType<T>): ComponentFactory<T>;
[key: string]: ComponentFactory<HTMLProps<any>>;
};
declare const posed: Posed;
export default posed;
JS示例如下:
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Link, Location } from '@reach/router';
import posed, { PoseGroup } from 'react-pose';
import Home from './pages/home';
import About from './pages/about';
import './styles.css';
const RouteContainer = posed.div({
enter: { opacity: 1, delay: 300, beforeChildren: 300 },
exit: { opacity: 0 }
});
const PosedRouter = ({ children }) => (
<Location>
{({ location }) => (
<PoseGroup>
<RouteContainer key={location.key}>
<Router location={location}>{children}</Router>
</RouteContainer>
</PoseGroup>
)}
</Location>
);
const App = () => (
<div id="site-container">
<header>
<h1>Route transitions with Pose and Reach Router</h1>
</header>
<div id="content-container">
<ul id="site-nav">
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
</ul>
<PosedRouter>
<Home path="/" />
<About path="/about" />
</PosedRouter>
</div>
</div>
);
ReactDOM.render(<App />, document.getElementById('root'));
https://popmotion.io/pose/examples/route-transitions-reach-router/
我被困在这里:
import * as React from 'react';
import { Router, Link, Location } from '@reach/router';
import { ComponentFactory } from 'react-pose/lib/posed';
import posed, { PoseGroup } from 'react-pose';
const RouteContainer: ComponentFactory<React.HTMLProps<any>> = posed.div({
enter: { opacity: 1, delay: 300, beforeChildren: 300 },
exit: { opacity: 0 }
});
const PosedRouter: Location = ({ children }: { children: React.ReactNode }) => (
<Location>
{({ location }) => (
<PoseGroup>
<RouteContainer key={location.key}>
<Router location={location}>{children}</Router>
</RouteContainer>
</PoseGroup>
)}
</Location>
);
打开
<RouteContainer key={location.key}>
键入'ComponentType<{[key:string]:any;children?:任何;姿势?:
字符串|字符串[]|未定义;_姿势?:string | string[]|未定义;
初始姿势?:string | string[]|未定义;是否具有父级?:布尔值|
未定义;onPoseComplete?:((姿势:string | string[])=>任意)|
可分配到“ComponentFactory>”类型。类型
'ComponentClass<{[键:字符串]:有;子级吗?:任何;姿势?:字符串|
字符串[]|未定义;_pose?:string | string[]|未定义;
未定义;onPoseComplete?:((姿势:string | string[])=>任意)|
未定义;onValueChange?:{…;}|未定义;内部…'不是
可分配到“ComponentFactory>”类型。
键入'ComponentClass<{[key:string]:any;children?:任何;姿势?:string | string[]|未定义;_姿势?:string | string[]|未定义;
初始姿势?:string | string[]|未定义;是否具有父级?:布尔值|
未定义;onPoseComplete?:((姿势:string | string[])=>任意)|
匹配签名'(poseConfig?:DomPopmotionConfig|
DomPopmotionConfigFactory>|未定义):
ComponentType<{[键:字符串]:任何;子级?:任何;姿势?:字符串|
字符串[]|未定义;_pose?:string | string[]|未定义。。。4个
更多…;innerRef?: { ...; } | ... 再来一个。。。|未定义;}&
PoseContextProps&HTMLProps<..>>'。
这让我很困惑,因为打字看起来是正确的。我不想使用匿名签名和保持强大的打字,这里。