Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to us latest React context to fix strict-mode warning #765

Closed
Closed
Show file tree
Hide file tree
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
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,51 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="1.12.0"></a>
# [1.12.0](https://github.com/clauderic/react-sortable-hoc/compare/v1.1.0...v1.12.0) (2020-12-29)


### Bug Fixes

* added prop-types to peerDependencies ([0e855c5](https://github.com/clauderic/react-sortable-hoc/commit/0e855c5))
* clear autoscroller when autoscroll is disabled ([#604](https://github.com/clauderic/react-sortable-hoc/issues/604)) ([3fd83f9](https://github.com/clauderic/react-sortable-hoc/commit/3fd83f9))
* copy canvas content into cloned node ([43ad122](https://github.com/clauderic/react-sortable-hoc/commit/43ad122))
* do not copy canvas context if it has neither width nor height ([#530](https://github.com/clauderic/react-sortable-hoc/issues/530)) ([3808437](https://github.com/clauderic/react-sortable-hoc/commit/3808437))
* don't spread the keysToOmit parameter in omit util ([#563](https://github.com/clauderic/react-sortable-hoc/issues/563)) ([1c69772](https://github.com/clauderic/react-sortable-hoc/commit/1c69772))
* Fix broken UMD build ([#587](https://github.com/clauderic/react-sortable-hoc/issues/587)) ([6cb7750](https://github.com/clauderic/react-sortable-hoc/commit/6cb7750))
* get updated index after updateBeforeSortStart ([4471a0a](https://github.com/clauderic/react-sortable-hoc/commit/4471a0a))
* helperContainer PropType definition broke server-side rendering ([#471](https://github.com/clauderic/react-sortable-hoc/issues/471)) ([c0eef97](https://github.com/clauderic/react-sortable-hoc/commit/c0eef97))
* invalid helperContainer PropType definition ([#493](https://github.com/clauderic/react-sortable-hoc/issues/493)) ([dc1d18f](https://github.com/clauderic/react-sortable-hoc/commit/dc1d18f))
* issue with cloning canvas context of dragged items ([#512](https://github.com/clauderic/react-sortable-hoc/issues/512)) ([4df34ad](https://github.com/clauderic/react-sortable-hoc/commit/4df34ad))
* issue with getComputedStyle and getScrollingParent ([b104249](https://github.com/clauderic/react-sortable-hoc/commit/b104249))
* issue with radio input name collision when cloning helper ([5337c97](https://github.com/clauderic/react-sortable-hoc/commit/5337c97))
* issue with windowAsScrollContainer and translation offsets ([0391e62](https://github.com/clauderic/react-sortable-hoc/commit/0391e62))
* lock axis story should not use lockToContainerEdges ([db1d3a9](https://github.com/clauderic/react-sortable-hoc/commit/db1d3a9))
* omit disableAutoscroll prop ([#502](https://github.com/clauderic/react-sortable-hoc/issues/502)) ([e994e73](https://github.com/clauderic/react-sortable-hoc/commit/e994e73))
* omit spreading helperContainer prop ([#497](https://github.com/clauderic/react-sortable-hoc/issues/497)) ([12bafdf](https://github.com/clauderic/react-sortable-hoc/commit/12bafdf))
* overflow bug while dragging an item upwards in a grid ([1a2c87e](https://github.com/clauderic/react-sortable-hoc/commit/1a2c87e))
* pass isKeySorting to onSortOver and updateBeforeSortStart handler props ([#531](https://github.com/clauderic/react-sortable-hoc/issues/531)) ([763fd33](https://github.com/clauderic/react-sortable-hoc/commit/763fd33))
* PropType definition for keyCodes was incorrect ([eaf5070](https://github.com/clauderic/react-sortable-hoc/commit/eaf5070))
* remove browser field with umd bundle ([#541](https://github.com/clauderic/react-sortable-hoc/issues/541)) ([d3b30fd](https://github.com/clauderic/react-sortable-hoc/commit/d3b30fd))
* replace process.env.NODE_ENV in UMD builds ([16135df](https://github.com/clauderic/react-sortable-hoc/commit/16135df))
* update helperContainer prop type definition ([#491](https://github.com/clauderic/react-sortable-hoc/issues/491)) ([fd30383](https://github.com/clauderic/react-sortable-hoc/commit/fd30383))
* updated the behaviour of disabled elements ([bd3d041](https://github.com/clauderic/react-sortable-hoc/commit/bd3d041))
* virtualized collection grid bug ([a57975c](https://github.com/clauderic/react-sortable-hoc/commit/a57975c))


### Features

* Add CSS Grid grid-gap support ([#657](https://github.com/clauderic/react-sortable-hoc/issues/657)) ([4efcaa2](https://github.com/clauderic/react-sortable-hoc/commit/4efcaa2))
* Add disableAutoscroll prop ([#484](https://github.com/clauderic/react-sortable-hoc/issues/484)) ([7845e76](https://github.com/clauderic/react-sortable-hoc/commit/7845e76))
* Add keyCodes prop to configure the keyboard shortcuts ([#588](https://github.com/clauderic/react-sortable-hoc/issues/588)) ([4c6d8dd](https://github.com/clauderic/react-sortable-hoc/commit/4c6d8dd))
* add support for keyboard sorting ([#501](https://github.com/clauderic/react-sortable-hoc/issues/501)) ([439b92f](https://github.com/clauderic/react-sortable-hoc/commit/439b92f))
* added helperContainer prop ([286eff4](https://github.com/clauderic/react-sortable-hoc/commit/286eff4))
* allow helperContainer prop to be a function returning an HTMLElement ([#489](https://github.com/clauderic/react-sortable-hoc/issues/489)) ([f4a9b4a](https://github.com/clauderic/react-sortable-hoc/commit/f4a9b4a))
* Detect scroll container automatically ([#507](https://github.com/clauderic/react-sortable-hoc/issues/507)) ([6572921](https://github.com/clauderic/react-sortable-hoc/commit/6572921))
* prevent sort start on contentEditable target ([d64c8cf](https://github.com/clauderic/react-sortable-hoc/commit/d64c8cf))



<a name="1.11.0"></a>

# [1.11.0](https://github.com/clauderic/react-sortable-hoc/compare/v1.10.1...v1.11.0) (2020-01-20)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-sortable-hoc",
"version": "1.11.0",
"version": "1.12.0",
"description": "Set of higher-order components to turn any list into a sortable, touch-friendly, animated list",
"author": {
"name": "Clauderic Demers",
Expand Down
31 changes: 16 additions & 15 deletions src/SortableContainer/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import {findDOMNode} from 'react-dom';
import invariant from 'invariant';

Expand Down Expand Up @@ -37,17 +36,24 @@ import {
defaultKeyCodes,
} from './props';

export const SortableContext = React.createContext({
manager: {},
});

export default function sortableContainer(
WrappedComponent,
config = {withRef: false},
) {
return class WithSortableContainer extends React.Component {
constructor(props) {
super(props);
const manager = new Manager();

validateProps(props);

this.manager = new Manager();
this.manager = manager;
this.wrappedInstance = React.createRef();
this.sortableContextValue = {manager};
this.events = {
end: this.handleEnd,
move: this.handleMove,
Expand All @@ -60,16 +66,7 @@ export default function sortableContainer(
static displayName = provideDisplayName('sortableList', WrappedComponent);
static defaultProps = defaultProps;
static propTypes = propTypes;
static childContextTypes = {
manager: PropTypes.object.isRequired,
};

getChildContext() {
return {
manager: this.manager,
};
}


componentDidMount() {
const {useWindowAsScrollContainer} = this.props;
const container = this.getContainer();
Expand Down Expand Up @@ -898,7 +895,7 @@ export default function sortableContainer(
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call',
);

return this.refs.wrappedInstance;
return this.wrappedInstance.current;
}

getContainer() {
Expand Down Expand Up @@ -1047,9 +1044,13 @@ export default function sortableContainer(
};

render() {
const ref = config.withRef ? 'wrappedInstance' : null;
const ref = config.withRef ? this.wrappedInstance : null;

return <WrappedComponent ref={ref} {...omit(this.props, omittedProps)} />;
return (
<SortableContext.Provider value={this.sortableContextValue}>
<WrappedComponent ref={ref} {...omit(this.props, omittedProps)} />
</SortableContext.Provider>
);
}

get helperContainer() {
Expand Down
16 changes: 7 additions & 9 deletions src/SortableElement/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import invariant from 'invariant';
import PropTypes from 'prop-types';
import * as React from 'react';
import {findDOMNode} from 'react-dom';
import invariant from 'invariant';

import {provideDisplayName, omit} from '../utils';
import {SortableContext} from '../SortableContainer';
import {omit, provideDisplayName} from '../utils';

const propTypes = {
index: PropTypes.number.isRequired,
Expand All @@ -23,9 +23,7 @@ export default function sortableElement(
WrappedComponent,
);

static contextTypes = {
manager: PropTypes.object.isRequired,
};
static contextType = SortableContext;

static propTypes = propTypes;

Expand Down Expand Up @@ -84,11 +82,11 @@ export default function sortableElement(
config.withRef,
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableElement() call',
);
return this.refs.wrappedInstance;
return this.wrappedInstance.current;
}

render() {
const ref = config.withRef ? 'wrappedInstance' : null;
const ref = config.withRef ? this.wrappedInstance : null;

return <WrappedComponent ref={ref} {...omit(this.props, omittedProps)} />;
}
Expand Down
12 changes: 7 additions & 5 deletions src/SortableHandle/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import {findDOMNode} from 'react-dom';
import invariant from 'invariant';
import * as React from 'react';
import { findDOMNode } from 'react-dom';
import { provideDisplayName } from '../utils';

import {provideDisplayName} from '../utils';

export default function sortableHandle(
WrappedComponent,
Expand All @@ -21,11 +21,13 @@ export default function sortableHandle(
config.withRef,
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableHandle() call',
);
return this.refs.wrappedInstance;
return this.wrappedInstance.current;
}

wrappedInstance = React.createRef();

render() {
const ref = config.withRef ? 'wrappedInstance' : null;
const ref = config.withRef ? this.wrappedInstance : null;

return <WrappedComponent ref={ref} {...this.props} />;
}
Expand Down
Loading