### Clone Repository and Run Examples
Source: https://github.com/reactjs/react-transition-group/blob/master/README.md
Instructions to clone the project repository and set up the development environment. This involves installing dependencies and running Storybook to view interactive examples.
```bash
git clone git@github.com:reactjs/react-transition-group.git
npm install
npm run storybook
```
--------------------------------
### Install TypeScript Definitions
Source: https://github.com/reactjs/react-transition-group/blob/master/README.md
Installs the TypeScript definitions for react-transition-group, enabling type checking and autocompletion in TypeScript projects. This is done via npm.
```bash
npm install @types/react-transition-group
```
--------------------------------
### React Component with CSSTransitionGroup
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
An example React component demonstrating the use of the older `CSSTransitionGroup` API to animate a list of items. It includes state management for the list and event handlers for adding/removing items.
```javascript
class TodoList extends React.Component {
constructor(props) {
super(props);
this.state = {items: ['hello', 'world', 'click', 'me']};
this.handleAdd = this.handleAdd.bind(this);
}
handleAdd() {
const newItems = this.state.items.concat([
prompt('Enter some text')
]);
this.setState({items: newItems});
}
handleRemove(i) {
let newItems = this.state.items.slice();
newItems.splice(i, 1);
this.setState({items: newItems});
}
render() {
const items = this.state.items.map((item, i) => (
this.handleRemove(i)}>
{item}
));
return (
{items}
);
}
}
```
--------------------------------
### Migrate CSSTransitionGroup to TransitionGroup
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Shows the initial step of migrating a React component by replacing `CSSTransitionGroup` with `TransitionGroup`. This change prepares the component for the newer animation API.
```diff
render() {
const items = this.state.items.map((item, i) => (
this.handleRemove(i)}>
{item}
));
return (
-
+
{items}
-
+
)
}
```
--------------------------------
### Use Custom FadeTransition Component
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Demonstrates how to use the custom `FadeTransition` component in place of direct `CSSTransition` usage. This refactoring makes the render method cleaner and centralizes transition configuration.
```diff
render() {
const items = this.state.items.map((item, i) => (
-
+
this.handleRemove(i)}>
{item}
-
+
));
return (
{items}
)
}
```
--------------------------------
### Wrap Items with CSSTransition
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Illustrates how to wrap individual list items with the `CSSTransition` component within `TransitionGroup`. This applies the specified animations to each item as it enters or leaves the list.
```diff
render() {
const items = this.state.items.map((item, i) => (
+
this.handleRemove(i)}>
{item}
+
));
return (
{items}
)
}
```
--------------------------------
### CSS Transitions for React Transition Group
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Defines the CSS classes required for entry and exit animations. It specifies opacity changes and transition durations for elements entering and leaving the DOM.
```css
.example-enter {
opacity: 0.01;
}
.example-enter.example-enter-active {
opacity: 1;
transition: opacity 500ms ease-in;
}
.example-leave {
opacity: 1;
}
.example-leave.example-leave-active {
opacity: 0.01;
transition: opacity 300ms ease-in;
}
```
--------------------------------
### Property Mappings: v1 to v2
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Details the property renames and changes required when migrating from react-transition-group v1 to v2. This includes changes to transition names, timeouts, and boolean flags.
```javascript
v1:
{items}
v2:
{items}
```
```javascript
v1:
transitionName -> classNames
transitionEnterTimeout, transitionLeaveTimeout -> timeout={{ exit, enter }}
transitionAppear -> appear
transitionEnter -> enter
transitionLeave -> exit
```
--------------------------------
### Update CSS from leave to exit
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Demonstrates the necessary CSS class name changes for the migration. The `leave` prefix is updated to `exit` to align with the newer `CSSTransition` component's naming convention.
```diff
.example-enter {
opacity: 0.01;
}
.example-enter.example-enter-active {
opacity: 1;
transition: opacity 500ms ease-in;
}
-.example-leave {
+.example-exit {
opacity: 1;
}
-.example-leave.example-leave-active {
+.example-exit.example-exit-active {
opacity: 0.01;
transition: opacity 300ms ease-in;
}
```
--------------------------------
### Create Reusable FadeTransition Component
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Defines a custom React component, `FadeTransition`, that encapsulates the `CSSTransition` logic with predefined `classNames` and `timeout` props. This promotes code reuse and simplifies transition application.
```javascript
const FadeTransition = (props) => (
);
```
--------------------------------
### Use Lifecycle Callbacks for React Transition States
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
Child lifecycle methods have been removed in v2. To perform actions during transition state changes (enter, exit), use the new lifecycle callback props: `onEnter`, `onEntering`, `onEntered`, `onExit`, `onExiting`, and `onExited`. Each callback receives the DOM node of the transition component.
```jsx
```
--------------------------------
### Wrap TransitionGroup with Transition Components in React
Source: https://github.com/reactjs/react-transition-group/blob/master/Migration.md
In v2, `` no longer manages transitions via custom child lifecycle methods. Instead, it requires children to be `` components. Props intended for the transition must be passed through from the ``'s children to the `` component itself, often using a spread operator.
```jsx
const MyTransition = ({ children: child, ...props }) => (
// NOTICE THE SPREAD! THIS IS REQUIRED!
{transitionState => React.cloneElement(child, {
style: getStyleForTransitionState(transitionState)
})}
);
const MyList = () => (
{items.map(item => (
{item}
)}
);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.