Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.

Commit 36ac9cc

Browse files
rouvenherzogovidiuch
authored andcommitted
Remove componentWillReceiveProps from Loader
1 parent ea55cad commit 36ac9cc

File tree

1 file changed

+34
-50
lines changed
  • packages/react-cosmos-loader/src/components/Loader

1 file changed

+34
-50
lines changed
Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,39 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import { func, object, arrayOf } from 'prop-types';
33
import createLinkedList from '@skidding/linked-list';
44
import { createModuleType } from '../../utils/module-type';
55
import { PropsProxy } from '../PropsProxy';
66

7-
export class Loader extends Component {
8-
static propTypes = {
9-
fixture: createModuleType(object).isRequired,
10-
proxies: arrayOf(createModuleType(func)),
11-
onComponentRef: func
12-
};
13-
14-
static defaultProps = {
15-
proxies: []
16-
};
17-
18-
/**
19-
* Loader for rendering React components in isolation.
20-
*
21-
* Renders components using fixtures and Proxy middleware. Initialized via
22-
* props.
23-
*/
24-
constructor(props) {
25-
super(props);
26-
27-
this.firstProxy = createProxyLinkedList(props.proxies);
28-
}
29-
30-
componentWillReceiveProps({ proxies }) {
31-
if (proxies !== this.props.proxies) {
32-
this.firstProxy = createProxyLinkedList(proxies);
33-
}
34-
}
35-
36-
render() {
37-
const { firstProxy } = this;
38-
const { fixture, onComponentRef, onFixtureUpdate } = this.props;
39-
40-
return (
41-
<firstProxy.value
42-
nextProxy={firstProxy.next()}
43-
fixture={fixture}
44-
onComponentRef={onComponentRef || noope}
45-
onFixtureUpdate={onFixtureUpdate || noope}
46-
/>
47-
);
48-
}
49-
}
50-
51-
function createProxyLinkedList(userProxies) {
52-
return createLinkedList([...userProxies, PropsProxy]);
53-
}
54-
55-
function noope() {}
7+
/**
8+
* Loader for rendering React components in isolation.
9+
*
10+
* Renders components using fixtures and Proxy middleware. Initialized via
11+
* props.
12+
*/
13+
const Loader = ({ fixture, proxies, onComponentRef, onFixtureUpdate }) => {
14+
const firstProxy = createLinkedList([...proxies, PropsProxy]);
15+
16+
return (
17+
<firstProxy.value
18+
nextProxy={firstProxy.next()}
19+
fixture={fixture}
20+
onComponentRef={onComponentRef}
21+
onFixtureUpdate={onFixtureUpdate}
22+
/>
23+
);
24+
};
25+
26+
Loader.propTypes = {
27+
fixture: createModuleType(object).isRequired,
28+
proxies: arrayOf(createModuleType(func)),
29+
onFixtureUpdate: func,
30+
onComponentRef: func
31+
};
32+
33+
Loader.defaultProps = {
34+
proxies: [],
35+
onFixtureUpdate: () => {},
36+
onComponentRef: () => {}
37+
};
38+
39+
export { Loader };

0 commit comments

Comments
 (0)