Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ React Flickity Component
[![dependencies](https://david-dm.org/theolampert/react-flickity-component.svg)](https://david-dm.org/theolampert/react-flickity-component)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

#### Introduction:
# Introduction:
A React.js Flickity component.

#### Install:
# Install:

```shell
npm install react-flickity-component --save
// Or
yarn add react-flickity-component
```

#### Usage:
# Usage:

```javascript
// Commonjs
Expand Down Expand Up @@ -47,27 +47,35 @@ function Carousel() {
}

```
#### Example usage:
### Example Usage:
See a codesandbox example here:
https://codesandbox.io/s/qlz12m4oj6

See an example in production with server side rendering [here](https://github.com/artsy/reaction/blob/master/src/Components/v2/CarouselV3.tsx#L160-L171)


#### Props:
### Props:

| Property | Type | Default | Description |
| -------------------- | -----------| --------|---------------------------------------------------------------|
| `className` | `String` | `''` | Applied to top level wrapper |
| `elementType` | `String` | `'div'` | Wrapper's element type |
| `options` | `Object` | `{}` | Flickity initialization opions |
| `disableImagesLoaded`| `Boolean` | `false` | Disable call `reloadCells` images are loaded |
| `reloadOnUpdate` | `Boolean` | `false` | Run `reloadCells` and `resize` on `componentDidUpdate` |
| `static` | `Boolean` | `false` | Carousel contents are static and not updated at runtime. Useful for smoother server-side rendering however the carousel contents cannot be updated dynamically. |
| `flickityRef` | `Function` | | like `ref` function, get Flickity instance in parent component|
| `flickityRef` | `Function` | | Like `ref` function, get Flickity instance in parent component|
| `reloadOnUpdate` | `Boolean` | `false` | **Read next section before you set this prop.** Run `reloadCells` and `resize` on `componentDidUpdate` |
| `static` | `Boolean` | `false` | **Read next section before you set this prop.** Carousel contents are static and not updated at runtime. Useful for smoother server-side rendering however the carousel contents cannot be updated dynamically. |

### How Does It Work

#### Use Flickity's API and events
Under the hood, react-flickity-component uses [portal](https://reactjs.org/docs/portals.html) to render children slides inside Flickity instance. The need for portal is because after Flickity is initialized, new DOM nodes(mostly Flickity wrapper elements) would be created, this changes the DOM hierarchy of the parent component, thus any future update, whether it's originated from Flickity, like adding/removing slides, or from parent, like a prop changes, will make React fail to reconcile for the DOM snapshot is out of sync.

#64 introduced a new prop to change the underlying render method: instead of portal, react-flickity-component will directly render children. This is create a smoother server-side rendering experience, but **please be aware using `static` prop possibly will cause all your future update to fail,** which means adding/removing slides will definitely fail to render, so use with caution.

However there is a fail-safe option `reloadOnUpdate`. It means every time there is a update, we tear down and set up Flickity. This will ensure that Flickity is always rendered correctly, but it's a rather costly operation and it will cause a flicker since DOM nodes are destroyed and recreated.


### Use Flickity's API and events

You can access Flickity instance with `flickityRef` prop just like `ref`, and use this instance to register events and use API.

Expand Down Expand Up @@ -103,7 +111,7 @@ class Carousel extends React.Component {
```


#### License Information:
# License Information:
[GPLv3](https://www.gnu.org/licenses/gpl-3.0.html)

Flickity may be used in commercial projects and applications with the one-time purchase of a commercial license.
Expand Down