Transform React component across routes with animations
This project is inspried by Vue Starport Project. Thanks all works from the authors.
The mainly work is done, but there are still some featues I have not implemented yet and no ideas. You can get the list in the below.
npm install @react-starport/core
yarn add @react-starport/core
pnpm add @react-starport/core
Add <StarportCarrier>
component from @react-starport/core
to your root component (App.tsx
). All <Starport>
usage should be inside <StarportCarrier>
component.
import { StarportCarrier } from '@react-starport/core';
function App() {
return (
<StarportCarrier> {{/* here */}}
<Outlet /> {/* Outlet comes from `react-router`, you can get detail from the doc */}
</StarportCarrier>
)
}
export default App;
In routes, wrap the component with the <Starport>
component.
/* PageA.jsx */
import { Starport } from '@react-starport/core';
function PageA() {
return (
<Starport port="my-id" style="height:400px">
<MyComponent />
</Starport>
)
}
On the other page, we do the same thing with the same port
id to identify the instance.
/* PageA.jsx */
import { Starport } from '@react-starport/core';
function PageB() {
return (
<Starport port="my-id" style="height:400px">
<MyComponent />
</Starport>
)
}
Note that you might need to apply some styles to
<Starport>
to make it have a defined size indicating the area for the "floating starcraft" to land.
Checkout the Playground for more examples.
import { StarportCarrier } from '@react-starport/core';
function App() {
const options = {
duration: 700,
easing: 'cubic-bezier(0.45, 0, 0.55, 1)',
}
return (
<StarportCarrier {...options }>
<Outlet />
</StarportCarrier>
)
}
export default App;
/* Page.jsx */
import { Starport } from '@react-starport/core';
function Page() {
const options = {
duration: 700,
easing: 'cubic-bezier(0.45, 0, 0.55, 1)',
}
return (
<Starport port="my-id" style="height:400px" { ...options }>
<MyComponent />
</Starport>
)
}
To debug what happens during the transition, you can add the follow CSS to highlight the parts
.debug .starport-craft {
background: #0805;
}
.debug .starport:not(.starport--landed) {
background: #8005;
}
- KeepAlive
- You can use global state as alternative
- InitialProps and MountedProps
- I haven't figured out what scenarios would use these configurations