MCPcopy Create free account
hub / github.com/Lobos/react-ui / fetchData

Method fetchData

src/higherOrders/Fetch.js:91–120  ·  view source on GitHub ↗
(fetch)

Source from the content-addressed store, hash-verified

89 }
90
91 fetchData (fetch) {
92 if (!fetch) {
93 return;
94 }
95
96 this.setState({ fetchStatus: FETCH_PENDING });
97
98 if (typeof fetch === 'function') {
99 fetch.then((data) => {
100 this.setData(data);
101 });
102 return;
103 }
104
105 if (typeof fetch === 'string') {
106 fetch = { url: fetch };
107 }
108 let { method='get', url, data, then, ...options } = fetch;
109 let request = refetch[method](url, data, options).then(peerData.bind(request));
110
111 // handle response
112 if (then) { request = request.then(then); }
113 request.then((data) => {
114 this.setData(data);
115 })
116 .catch((err) => {
117 console.warn(err);
118 this.setData(new Error());
119 });
120 }
121
122 setData (data) {
123 if (!this._isMounted) {

Callers 2

componentWillMountMethod · 0.95

Calls 1

setDataMethod · 0.95

Tested by

no test coverage detected