ReactJS: Fetch in bootstrap modal after an initial fetch - reactjs

I have used fetch to render my database in a table, I was trying to use bootstrap modal to render an specific document and edit it to post again in database. I think these two calls to the server overcharge it, and then it can't render the components, I just want to make sure if there is another way to do make the second call. When I run this display the result is:
Unhandled Rejection (TypeError): Failed to fetch
callApi
5 | Accept: "application/json",
6 | };
7 |
8 | const response = await fetch("http://localhost:3002/api" + url, options);
| ^ 9 | const data = await response.json();
10 | return data;
11 |
View compiled
list
.../src/api.js:29
26 | },
27 | sales: {
28 | list() {
29 | return callApi("/sales")
| ^ 30 | },
31 | create(sale) {
32 | return callApi("/sales", {
View compiled
fetchData
.../src/screens/sales/SalesScreen.js:29
26 |
27 | useEffect(() => {
28 | const fetchData = async () => {
29 | const response = await api.sales.list();
| ^ 30 | setSales(response);
31 | console.log(sales);
32 | const responseUsers = await api.users.list();
View compiled
(anonymous function)
.../src/screens/sales/SalesScreen.js:37
34 | console.log(users);
35 | };
36 |
37 | fetchData();
| ^ 38 | }, []);
39 |
40 | return (
View compiled
▶ 11 stack frames were collapsed.
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.

Related

fetchMock error on testing RTK-query with jest (react Vite.js)

just tried to mocked the store then test the request with fetchMock but got this error :
you can check out the full repo on :
https://github.com/alibidjandy/layered-architecture
src/app/main/__tests__/main.test.tsx (5.569 s)
● Console
console.warn
Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.
7 | reducerPath: "productService",
8 | tagTypes: ["product"],
> 9 | baseQuery: fetchBaseQuery({
| ^
10 | baseUrl: serviceURL,
11 | }),
12 | endpoints: (builder) => ({}),
at fetchBaseQuery (node_modules/#reduxjs/toolkit/src/query/fetchBaseQuery.ts:180:13)
at Object.<anonymous> (src/app/main/data/api/service.ts:9:28)
at Object.<anonymous> (src/app/main/data/api/store.ts:3:1)
FAIL src/app/components/products/tests/products-requests.test.tsx
● Test suite failed to run
src/app/components/products/__tests__/products-requests.test.tsx:14:3 - error TS2304: Cannot find name 'fetchMock'.
14 fetchMock.resetMocks();
~~~~~~~~~
src/app/components/products/__tests__/products-requests.test.tsx:24:5 - error TS2304: Cannot find name 'fetchMock'.
24 fetchMock.mockResponse(JSON.stringify(dummyProducts));
~~~~~~~~~
src/app/components/products/__tests__/products-requests.test.tsx:41:5 - error TS2304: Cannot find name 'fetchMock'.
41 fetchMock.mockReject(new Error("Internal Server Error"));
~~~~~~~~~
src/app/components/products/__tests__/products-requests.test.tsx:61:5 - error TS2304: Cannot find name 'fetchMock'.
61 fetchMock.mockResponse(JSON.stringify(dummyProducts));
~~~~~~~~~
src/app/components/products/__tests__/products-requests.test.tsx:85:5 - error TS2304: Cannot find name 'fetchMock'.
85 fetchMock.mockReject(new Error("Internal Server Error"));
~~~~~~~~~
FAIL src/app/main/tests/service.test.ts (15.706 s)
● getProductById › request is correct
expect(jest.fn()).toBeCalledTimes(expected)
Expected number of calls: 1
Received number of calls: 0
20 | .dispatch<any>(getProducts.initiate(undefined))
21 | .then(() => {
> 22 | expect(fetchMock).toBeCalledTimes(1);
| ^
23 | const { method, url } = fetchMock.mock.calls[0][0] as Request;
24 |
25 | expect(method).toBe("GET");
at src/app/main/__tests__/service.test.ts:22:27
● getProductById › unsuccessful response
TypeError: Cannot read property 'error' of undefined
51 | const {
52 | status,
> 53 | error: { error },
| ^
54 | isError,
55 | } = action;
56 | expect(status).toBe("rejected");
at src/app/main/__tests__/service.test.ts:53:20
● getProductById › request is correct
expect(jest.fn()).toBeCalledTimes(expected)
Expected number of calls: 1
Received number of calls: 0
69 | .dispatch<any>(getProductById.initiate(dummyProduct.id))
70 | .then(() => {
> 71 | expect(fetchMock).toBeCalledTimes(1);
| ^
72 | const request = fetchMock.mock.calls[0][0] as Request;
73 | const { method, url } = request;
74 |
at src/app/main/__tests__/service.test.ts:71:27
● getProductById › unsuccessful response
TypeError: Cannot read property 'error' of undefined
102 | const {
103 | status,
> 104 | error: { error },
| ^
105 | isError,
106 | } = action;
107 | expect(status).toBe("rejected");
at src/app/main/__tests__/service.test.ts:104:20
Test Suites: 2 failed, 1 passed, 3 total
Tests: 4 failed, 3 passed, 7 total
Snapshots: 0 total
Time: 17.642 s
Ran all test suites.
install whatwg-fetch
after install it add import 'whatwg-fetch'; at the beginning (line 1) of the file.test youre using
The test in Jest doesn't run on the browser. It runs on NodeJS. So, you need a polyfill for the "fetch".
There are many options on NPM, but some of them haven't worked for me.
The one that worked fine was the cross-fetch: https://www.npmjs.com/package/cross-fetch
It works on browser/NodeJS/Mobile. You just need to add it to package.json (devDependencies) and import it on jest.setup.js file:
import 'cross-fetch/polyfill';

How to convert Image Slider Javascript code to reactjs using Hooks

I am trying to convert the JavaScript sample code in ReactJS.
The compiler doesn't display any error but browser is throwing an error at runtime.
I am using this example, please see below.
https://codepen.io/kathykato/pen/prEmKe
I expect to see it workable as displays in above example but I am getting small errors.
What I have tried so far is given below
-------------------------Carousel.js--------------------------
import React, { useState, useEffect } from "react";
import './Carousel.scss'
const Carousel = () => {
const items = document.querySelectorAll('img');
const itemCount = items.length;
const nextItem = document.querySelector('.next');
const previousItem = document.querySelector('.previous');
let count = 0;
// Similar to componentDidMount and componentDidUpdate:
useEffect(() => {
nextItem.addEventListener('click', showNextItem);
previousItem.addEventListener('click', showPreviousItem);
document.addEventListener('keydown', keyPress);
// clean up
return () => {
nextItem.removeEventListener('click', showNextItem);
previousItem.removeEventListener('click', showPreviousItem);
document.removeEventListener('keydown', keyPress);
};
})
function showNextItem() {
items[count].classList.remove('active');
if(count < itemCount - 1) {
count++;
} else {
count = 0;
}
items[count].classList.add('active');
console.log(count);
}
function showPreviousItem() {
items[count].classList.remove('active');
if(count > 0) {
count--;
} else {
count = itemCount - 1;
}
items[count].classList.add('active');
console.log(count);
}
function keyPress(e) {
e = e || window.event;
if (e.keyCode == '37') {
showPreviousItem();
} else if (e.keyCode == '39') {
showNextItem();
}
}
// nextItem.addEventListener('click', showNextItem);
// previousItem.addEventListener('click', showPreviousItem);
// document.addEventListener('keydown', keyPress);
return (
<div className="container">
<div className="slider">
<img className="active" src="https://source.unsplash.com/gKk9rpyDryU" alt="Nothing " />
<img src="https://source.unsplash.com/VFGEhLznjPU" alt="Nothing"/>
<img src="https://source.unsplash.com/InR-EhiO_js" alt="Nothing"/>
</div>
<nav className="slider-nav">
<ul>
<li className="arrow">
<button className="previous">
<span>
<i className="ion-arrow-left-c"></i>
</span>
</button>
</li>
<li className="arrow">
<button className="next">
<span>
<i className="ion-arrow-right-c"></i>
</span>
</button>
</li>
</ul>
</nav>
</div>
);
}
export default Carousel;
Application built with
{
"react": "16.13.0",
"react-dom": "^16.13.0",
"react-redux": "^7.2.0",
"redux": "^4.0.4"
"#material-ui/core": "^4.9.5"
}
Now see the errors below:
TypeError: Cannot read property 'addEventListener' of null
(anonymous function)
H:/ReactJs/Source Codes/react-master/react-master/src/components/Sliders/Carousel.js:14
11 |
12 | // Similar to componentDidMount and componentDidUpdate:
13 | useEffect(() => {
> 14 | nextItem.addEventListener('click', showNextItem);
| ^ 15 | previousItem.addEventListener('click', showPreviousItem);
16 | document.addEventListener('keydown', keyPress);
17 |
View compiled
commitHookEffectListMount
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:19731
19728 | if ((effect.tag & tag) === tag) {
19729 | // Mount
19730 | var create = effect.create;
> 19731 | effect.destroy = create();
| ^ 19732 |
19733 | {
19734 | var destroy = effect.destroy;
View compiled
commitPassiveHookEffects
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:19769
19766 | // before calling any create functions. The current approach only serializes
19767 | // these for a single fiber.
19768 | commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
> 19769 | commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
| ^ 19770 | break;
19771 | }
19772 | }
View compiled
HTMLUnknownElement.callCallback
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:188
185 | window.event = windowEvent;
186 | }
187 |
> 188 | func.apply(context, funcArgs);
| ^ 189 | didError = false;
190 | } // Create a global error event handler. We use this to capture the value
191 | // that was thrown. It's possible that this error handler will fire more
View compiled
invokeGuardedCallbackDev
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:237
234 | // errors, it will trigger our global error handler.
235 |
236 | evt.initEvent(evtType, false, false);
> 237 | fakeNode.dispatchEvent(evt);
| ^ 238 |
239 | if (windowEventDescriptor) {
240 | Object.defineProperty(window, 'event', windowEventDescriptor);
View compiled
invokeGuardedCallback
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:292
289 | function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
290 | hasError = false;
291 | caughtError = null;
> 292 | invokeGuardedCallbackImpl$1.apply(reporter, arguments);
293 | }
294 | /**
295 | * Same as invokeGuardedCallback, but instead of returning an error, it stores
View compiled
flushPassiveEffectsImpl
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:22853
22850 | while (_effect2 !== null) {
22851 | {
22852 | setCurrentFiber(_effect2);
> 22853 | invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
| ^ 22854 |
22855 | if (hasCaughtError()) {
22856 | if (!(_effect2 !== null)) {
View compiled
unstable_runWithPriority
H:/ReactJs/Source Codes/react-master/react-master/node_modules/scheduler/cjs/scheduler.development.js:653
650 | currentPriorityLevel = priorityLevel;
651 |
652 | try {
> 653 | return eventHandler();
| ^ 654 | } finally {
655 | currentPriorityLevel = previousPriorityLevel;
656 | }
View compiled
runWithPriority$1
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:11039
11036 |
11037 | function runWithPriority$1(reactPriorityLevel, fn) {
11038 | var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
> 11039 | return Scheduler_runWithPriority(priorityLevel, fn);
11040 | }
11041 | function scheduleCallback(reactPriorityLevel, callback, options) {
11042 | var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
View compiled
flushPassiveEffects
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:22820
22817 | if (pendingPassiveEffectsRenderPriority !== NoPriority) {
22818 | var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority ? NormalPriority : pendingPassiveEffectsRenderPriority;
22819 | pendingPassiveEffectsRenderPriority = NoPriority;
> 22820 | return runWithPriority$1(priorityLevel, flushPassiveEffectsImpl);
22821 | }
22822 | }
22823 |
View compiled
(anonymous function)
H:/ReactJs/Source Codes/react-master/react-master/node_modules/react-dom/cjs/react-dom.development.js:22699
22696 | if (!rootDoesHavePassiveEffects) {
22697 | rootDoesHavePassiveEffects = true;
22698 | scheduleCallback(NormalPriority, function () {
> 22699 | flushPassiveEffects();
| ^ 22700 | return null;
22701 | });
22702 | }
View compiled
workLoop
H:/ReactJs/Source Codes/react-master/node_modules/scheduler/cjs/scheduler.development.js:597
594 | currentPriorityLevel = currentTask.priorityLevel;
595 | var didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
596 | markTaskRun(currentTask, currentTime);
> 597 | var continuationCallback = callback(didUserCallbackTimeout);
| ^ 598 | currentTime = exports.unstable_now();
599 |
600 | if (typeof continuationCallback === 'function') {
View compiled
flushWork
H:/ReactJs/Source Codes/react-master/node_modules/scheduler/cjs/scheduler.development.js:552
549 | try {
550 | if (enableProfiling) {
551 | try {
> 552 | return workLoop(hasTimeRemaining, initialTime);
| ^ 553 | } catch (error) {
554 | if (currentTask !== null) {
555 | var currentTime = exports.unstable_now();
View compiled
MessagePort.performWorkUntilDeadline
C:/ReactJs/Source Codes/react-master/node_modules/scheduler/cjs/scheduler.development.js:164
161 | var hasTimeRemaining = true;
162 |
163 | try {
> 164 | var hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
| ^ 165 |
166 | if (!hasMoreWork) {
167 | isMessageLoopRunning = false;
Thank you
First, you're using React so prefer using React handlers like the following :
const nextItem = document.querySelector('.next');
nextItem.addEventListener('click', showNextItem);
becomes :
<button className="next" onClick={showNextitem}>
<span>
<i className="ion-arrow-right-c"></i>
</span>
</button>
you need to read some articles about event handling in react.
useEffect needs an empty array as second param to work like componentDidMount.
useEffect(() => {
document.addEventListener('keydown', keyPress);
// clean up
return () => {
document.removeEventListener('keydown', keyPress);
};
},[])
then as Marc Charpentier has said you add onClick={functionName} to the html element.
The reason that you receive the error is that a functional component does not have lifecycle (unlike class component) and it runs line after line.
which means when this line
nextItem.addEventListener('click', showNextItem);
is executed, the component has not returned any html element and it's not rendered in DOM. it does not exist yet so it's null.
and as you can read from the error message Cannot read property 'addEventListener' of null it can not find addEventListener in null

received Error: failed to invert matrix when add in deckGL in Reactjs hooks

im new in reactjs and deckGL and im having a little problem with the code below. I am trying to add DeckGL with FlyToInterpolator to center the marker. I'm receiving this error after I clicked the button, but when i'm using the react-map-gl + FlyToInterpolator it works.
update: the issue is, I having a problem when using FlyToInterpolar API in deckGL, but I have no issue using FlyToInterpolar in react-map-gl.
Please help! thank you very much
p/s: sorry english is not my main language.
error:
Error: failed to invert matrix
▶ 3 stack frames were collapsed.
Mapbox._updateMapViewport
src/mapbox/mapbox.js:434
431 | newViewState.altitude !== oldViewState.altitude;
432 |
433 | if (viewportChanged) {
> 434 | this._map.jumpTo(this._viewStateToMapboxProps(newViewState));
| ^ 435 |
436 | // TODO - jumpTo doesn't handle altitude
437 | if (newViewState.altitude !== oldViewState.altitude) {
View compiled
Mapbox._update
src/mapbox/mapbox.js:400
397 | newProps = Object.assign({}, this.props, newProps);
398 | checkPropTypes(newProps, 'Mapbox');
399 |
> 400 | const viewportChanged = this._updateMapViewport(oldProps, newProps);
| ^ 401 | const sizeChanged = this._updateMapSize(oldProps, newProps);
402 |
403 | if (!newProps.asyncRender && (viewportChanged || sizeChanged)) {
View compiled
Mapbox.setProps
src/mapbox/mapbox.js:213
210 | }
211 |
212 | setProps(props: Props) {
> 213 | this._update(this.props, props);
| ^ 214 | return this;
215 | }
216 |
View compiled
StaticMap._updateMapProps
src/components/static-map.js:213
210 | if (!this._mapbox) {
211 | return;
212 | }
> 213 | this._mapbox.setProps(
| ^ 214 | Object.assign({}, props, {
215 | width: this._width,
216 | height: this._height
View compiled
StaticMap.componentDidUpdate
src/components/static-map.js:152
149 | componentDidUpdate(prevProps: StaticMapProps) {
150 | if (this._mapbox) {
151 | this._updateMapStyle(prevProps, this.props);
> 152 | this._updateMapProps(this.props);
| ^ 153 | }
154 | }
155 |
View compiled
▶ 19 stack frames were collapsed.
DeckGL._customRender
src/deckgl.js:148
145 | // Viewports have changed, update children props first.
146 | // This will delay the Deck canvas redraw till after React update (in componentDidUpdate)
147 | // so that the canvas does not get rendered before the child components update.
> 148 | this.forceUpdate();
| ^ 149 | } else {
150 | this._redrawDeck();
151 | }
View compiled
Deck.redraw
src/lib/deck.js:351
348 |
349 | this.stats.get('Redraw Count').incrementCount();
350 | if (this.props._customRender) {
> 351 | this.props._customRender(redrawReason);
| ^ 352 | } else {
353 | this._drawLayers(redrawReason);
354 | }
View compiled
Deck._onRenderFrame
src/lib/deck.js:707
704 | this._pickAndCallback();
705 |
706 | // Redraw if necessary
> 707 | this.redraw(false);
| ^ 708 |
709 | // Update viewport transition if needed
710 | // Note: this can trigger `onViewStateChange`, and affect layers
View compiled
AnimationLoop.onRender
src/lib/animation-loop.js:252
249 | }
250 |
251 | onRender(...args) {
> 252 | return this.props.onRender(...args);
| ^ 253 | }
254 |
255 | onFinalize(...args) {
View compiled
AnimationLoop._renderFrame
src/lib/animation-loop.js:340
337 | }
338 |
339 | // call callback
> 340 | this.onRender(...args);
| ^ 341 | // end callback
342 | }
343 |
View compiled
AnimationLoop.redraw
src/lib/animation-loop.js:178
175 | this._setupFrame();
176 | this._updateCallbackData();
177 |
> 178 | this._renderFrame(this.animationProps);
| ^ 179 |
180 | // clear needsRedraw flag
181 | this._clearNeedsRedraw();
View compiled
renderFrame
src/lib/animation-loop.js:279
276 | if (!this._running) {
277 | return;
278 | }
> 279 | this.redraw();
| ^ 280 | this._animationFrameId = this._requestAnimationFrame(renderFrame);
281 | };
282 |
View compiled
Code:
const MAPBOX_TOKEN = // Set your mapbox token here
const useStyles = makeStyles({
box: {
borderStyle: "solid",
position: "absolute",
top: 0,
right: 0,
left: 0,
bottom: 0,
zIndex: -1
},
})
const MapHooks = forwardRef((props, ref) => {
const [fleetDetail, setFleetDetail] = useState(null)
const [mapRef, setMapRef] = useState(null);
const classes = useStyles()
const sigfox = ApiSigfox()
const [mapping, setMapping] = useState({
width: '100%',
height: '100%',
longitude: -73.989308,
latitude: 40.741895,
zoom: 12
});
useImperativeHandle(ref, () => ({
_goToNYC(e) {
Object.values(sigfox).map((docs) => {
return (e === docs.device) ? (
updateMap(docs)
) : null
})
}
}));
//update Map
function updateMap(test){
console.log(test.device + '-' + 'updateMap')
const viewport = {
...mapping,
longitude: test.lon,
latitude: test.lat,
zoom: 14,
transitionDuration: 2000,
transitionInterpolator: new FlyToInterpolator(),
transitionEasing: d3.easeCubic
};
setMapping(viewport)
console.log(mapping)
}
return (
<div className={classes.box} style={{borderStyle: "solid"}}>
<DeckGL viewState={mapping} controller={true} onViewStateChange={setMapping}>
<StaticMap
mapStyle="mapbox://styles/mapbox/streets-v11"
mapboxApiAccessToken={MAPBOX_TOKEN}
>
{Object.values(sigfox).map((docs) => {
return (docs.status !== 255 && (docs.lat >= -90 && docs.lat <= 90) ) ?
<Marker
key={docs.id}
latitude={docs.lat}
longitude={docs.lon}
offsetTop={-35}
offsetLeft={-8}
>
<div>
<button onClick={e => {e.preventDefault(); setFleetDetail(docs)}}>{docs.device}</button>
</div>
</Marker>
: null
})}
{/* display the pop up detail when click the icon */}
{fleetDetail ? (
<Popup
latitude={fleetDetail.lat}
longitude={fleetDetail.lon}
onClose={()=>{
setFleetDetail(null)
}}
>
<div>
<p>Device:{fleetDetail.device}</p>
<p>Latitude:{fleetDetail.lat}</p>
<p>Longitude:{fleetDetail.lon}</p>
<p>status:{fleetDetail.status}</p>
</div>
</Popup>
): null}
</StaticMap>
</DeckGL>
</div>
);
})
Thank you very much :)

TypeError: Unable to set property 'props' of undefined or null reference [duplicate]

This question already has an answer here:
React-router: TypeError: Cannot set property 'props' of undefined
(1 answer)
Closed 3 years ago.
I m not able to figure out how to resolve this error previously it was not there.If m trying to make constructor.
Previously i have imported React twice
import React from 'react';
import React,{Component} from 'react';
because of which error was there. To correct it i have removed 1 import from the code.
import React,{Component} from 'react';
import './App.css';
class App extends Component() {
constructor(props){
}
render() {
return (
<div className="App">
<table className="titleBar">
<tbody>
<tr>
<td>
<img alt="app icon" width="50" src="primary_green.svg"/>
</td>
<td width="8"/>
<td>
<h1>MovieDb Search</h1>
</td>
</tr>
</tbody>
</table>
<input style={{
fontSize: 24,
display: 'block',
width: '99%',
paddingTop: 8,
paddingBottom: 8,
paddingLeft: 16
}} placeholder="Enter Search Term"/>
</div>
);
}
}
export default App;
×
TypeError: Unable to set property 'props' of undefined or null reference
Component
C:/Users/Admin/Desktop/React_Projects/movies_search/node_modules/react/cjs/react.development.js:298
295 | */
296 |
297 | function Component(props, context, updater) {
> 298 | this.props = props;
| ^
299 | this.context = context; // If a component has string refs, we will assign a different object later.
300 |
301 | this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the
View compiled
./src/App.js
C:/Users/Admin/Desktop/React_Projects/movies_search/src/App.js:6
3 | import './App.css';
4 |
5 |
> 6 | class App extends Component() {
7 | constructor(props){
8 |
9 | }
View compiled
__webpack_require__
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:781
778 | };
779 |
780 | // Execute the module function
> 781 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^
782 |
783 | // Flag the module as loaded
784 | module.l = true;
View compiled
fn
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:149
146 | );
147 | hotCurrentParents = [];
148 | }
> 149 | return __webpack_require__(request);
| ^
150 | };
151 | var ObjectFactory = function ObjectFactory(name) {
152 | return {
View compiled
./src/index.js
http://localhost:3000/static/js/main.chunk.js:263:22
__webpack_require__
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:781
778 | };
779 |
780 | // Execute the module function
> 781 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^
782 |
783 | // Flag the module as loaded
784 | module.l = true;
View compiled
fn
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:149
146 | );
147 | hotCurrentParents = [];
148 | }
> 149 | return __webpack_require__(request);
| ^
150 | };
151 | var ObjectFactory = function ObjectFactory(name) {
152 | return {
View compiled
0
http://localhost:3000/static/js/main.chunk.js:390:1
__webpack_require__
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:781
778 | };
779 |
780 | // Execute the module function
> 781 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^
782 |
783 | // Flag the module as loaded
784 | module.l = true;
View compiled
checkDeferredModules
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
> 45 | result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
| ^
46 | }
47 | }
48 | return result;
View compiled
webpackJsonpCallback
C:/Users/Admin/Desktop/React_Projects/movies_search/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
> 32 | return checkDeferredModules();
| ^
33 | };
34 | function checkDeferredModules() {
35 | var result;
View compiled
Global code
http://localhost:3000/static/js/main.chunk.js:1:2
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.
When defining your App you are invoking Component as a function. Change
class App extends Component() {
to
class App extends Component {
Besides, it makes sense to remove the constructor if it is just empty.

Error in reactjs +materail-ui

I am getting this error while building a simple app which has two routes one to '/' and other to '/search'. I have used various components of material-ui.
The problem is when I route to '/search' the following error is thrown:
I have tried all necessary things but unable to figure out what's wrong?
I am just posting half of code here:
function capitalizeFirstLetter(string) {
28 | process.env.NODE_ENV !== "production" ? (0, _warning2.default)(typeof string === 'string', 'Material-UI: capitalizeFirstLetter(string) expects a string argument.') : void 0;
29 |
> 30 | return string.charAt(0).toUpperCase() + string.slice(1);
31 | } // weak
32 |
33 | function contains(obj, pred) {
View compiled
Typography
node_modules/material-ui/Typography/Typography.js:114
111 | other = (0, _objectWithoutProperties3.default)(props, ['align', 'classes', 'className', 'component', 'color', 'gutterBottom', 'headlineMapping', 'noWrap', 'paragraph', 'type']);
112 |
113 |
> 114 | var className = (0, _classnames2.default)(classes.root, classes[type], (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['color' + (0, _helpers.capitalizeFirstLetter)(color)], color !== 'default'), (0, _defineProperty3.default)(_classNames, classes.noWrap, noWrap), (0, _defineProperty3.default)(_classNames, classes.gutterBottom, gutterBottom), (0, _defineProperty3.default)(_classNames, classes.paragraph, paragraph), (0, _defineProperty3.default)(_classNames, classes['align' + (0, _helpers.capitalizeFirstLetter)(align)], align !== 'inherit'), _classNames), classNameProp);
115 |
116 | var Component = componentProp || (paragraph ? 'p' : headlineMapping[type]) || 'span';
117 |
View compiled
mountIndeterminateComponent
node_modules/react-dom/cjs/react-dom.development.js:8032
8029 | warning(false, "The <%s /> component appears to have a render method, but doesn't extend React.Component. " + 'This is likely to cause errors. Change %s to extend React.Component instead.', componentName, componentName);
8030 | }
8031 | ReactCurrentOwner.current = workInProgress;
> 8032 | value = fn(props, context);
8033 | }
8034 | // React DevTools reads this flag.
8035 | workInProgress.effectTag |= PerformedWork;
View compiled
beginWork
node_modules/react-dom/cjs/react-dom.development.js:8221
8218 |
8219 | switch (workInProgress.tag) {
8220 | case IndeterminateComponent:
> 8221 | return mountIndeterminateComponent(current, workInProgress, renderExpirationTime);
8222 | case FunctionalComponent:
8223 | return updateFunctionalComponent(current, workInProgress);
I see in Typography.js that it use capitalizeFirstLetter for color and align.
Check if you inserted there something that is not a string.

Resources