Skip to content

Commit b7fa131

Browse files
committed
Update README.md
1 parent 9cf6ed5 commit b7fa131

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

README.md

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,22 @@ ReactDOM.render(
131131
### Uncontrolled Component
132132
```js
133133
import React from 'react';
134+
import ReactDOM from 'react-dom';
134135
import Sortable from 'react-sortablejs';
135136

136137
class App extends React.Component {
137138
state = {
138139
items: ['Apple', 'Banana', 'Cherry', 'Guava', 'Peach', 'Strawberry']
139140
};
140-
141-
sortable = null;
142-
143-
handleReverseOrder() {
144-
const order = this.sortable.toArray();
145-
this.sortable.sort(order.reverse());
146-
}
141+
147142
render() {
148143
const items = this.state.items.map((val, key) => (<li key={key} data-id={val}>{val}</li>));
149-
150-
retrun (
144+
145+
return (
151146
<div>
152-
<button type="button" onClick={::this.handleReverseOrder}>Reverse Order</button>
153147
<Sortable
154148
// See all Sortable options at https://github.com/RubaXa/Sortable#options
155149
options={{
156-
handle: ".my-handle", // Drag handle selector within list items
157-
draggable: ".item" // Specifies which items inside the element should be sortable
158-
}}
159-
ref={(c) => {
160-
if (c) {
161-
this.sortable = sortable;
162-
}
163150
}}
164151
tag="ul" // Defaults to "div"
165152
>
@@ -169,44 +156,36 @@ class App extends React.Component {
169156
);
170157
}
171158
}
159+
160+
ReactDOM.render(
161+
<App />,
162+
document.getElementById('container')
163+
);
172164
```
173165

174166
### Controlled Component
175167

176168
```js
177169
import React from 'react';
178-
import Sortable from 'react-sortablejs';
170+
import ReactDOM from 'react-dom';
171+
import Sortable from '../src';
179172

180173
class App extends React.Component {
181174
state = {
182175
items: ['Apple', 'Banana', 'Cherry', 'Guava', 'Peach', 'Strawberry']
183176
};
184-
185-
sortable = null;
186-
187-
handleReverseOrder() {
188-
const order = this.sortable.toArray();
189-
this.sortable.sort(order.reverse());
190-
}
177+
191178
render() {
192179
const items = this.state.items.map((val, key) => (<li key={key} data-id={val}>{val}</li>));
193-
194-
retrun (
180+
181+
return (
195182
<div>
196-
<button type="button" onClick={::this.handleReverseOrder}>Reverse Order</button>
197183
<Sortable
198184
// See all Sortable options at https://github.com/RubaXa/Sortable#options
199185
options={{
200-
handle: ".my-handle", // Drag handle selector within list items
201-
draggable: ".item" // Specifies which items inside the element should be sortable
202-
}}
203-
ref={(c) => {
204-
if (c) {
205-
this.sortable = sortable;
206-
}
207186
}}
208187
tag="ul" // Defaults to "div"
209-
onChange={(order, sortable) { // [Optional] Controlled Component
188+
onChange={(order, sortable) => {
210189
this.setState({ items: order });
211190
}}
212191
>
@@ -216,6 +195,11 @@ class App extends React.Component {
216195
);
217196
}
218197
}
198+
199+
ReactDOM.render(
200+
<App />,
201+
document.getElementById('container')
202+
);
219203
```
220204

221205
### Shared Group

0 commit comments

Comments
 (0)