使用您的阵营程序是自举injectGlobal()
风格组分的辅助方法。使用这种方法,您可以设置任何CSS选择器的样式,就好像您使用传统的CSS一样。
首先创建一个JS文件导出文本与CSS的react-transition-group
模板(请不是我使用V2.1新的类名语法):上然后
globalCss.js
const globalCss = `
.transition-classes {
/* The double class name is to add more specifity */
/* so that this CSS has preference over the component one. */
/* Try removing it, you may not need it if properties don't collide */
/* https://www.styled-components.com/docs/advanced#issues-with-specificity */
&-enter&-enter {
}
&-enter&-enter-active {
}
&-exit&-exit {
}
&-exit&-exit-active {
}
}
`;
export default globalCss;
您入口点文件:
index.jsx
import { injectGlobal } from "styled-components";
import globalCss from "./globalCss.js";
injectGlobal`${ globalCss }`; // <-- This will do the trick
ReactDOM.render(
<Provider store={ Store } >
<HashRouter >
<Route path="/" component={ Component1 } />
<Route path="/" component={ Component2 } />
</HashRouter>
</Provider>,
document.getElementsByClassName("react-app")[0]
);
但是,即使使用样式化组件,如果您只是使用CSS/SASS/Less编写react-trasition-group
的类,它也可以很好地工作。