https://jestjs.io/docs/getting-started
npm i jest --save-dev
npm i supertest --save-dev
https://jestjs.io/docs/getting-started
npm i jest --save-dev
npm i supertest --save-dev
Node.js server and React client:
Node.js server and React client:
//
Extract unique values from arr1:
https://stackoverflow.com/questions/66527958/only-add-item-to-array-if-unique-otherwise-delete-react
https://stackoverflow.com/questions/11246758/how-to-get-unique-values-in-an-array
https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates
https://stackoverflow.com/questions/15125920/how-to-get-distinct-values-from-an-array-of-objects-in-javascript
- function to generate unique keys/ids/numbers/strings and use that
- existing npm packages like uuid, uniqid, etc
- generate random number `key-${new Date().getTime()}` with prefix from item being iterated
- using the unique ID from the database
Append arr2 elements to arr: (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Append arr2 array to arr: (4) [Array(4), Array(4), Array(4), Array(4)]
Save search term state to React Hooks with spread operator and wrapper function
https://stackoverflow.com/questions/54676966/push-method-in-react-hooks-usestate
https://javascript.plainenglish.io/how-to-add-to-an-array-in-react-state-3d08ddb2e1dc
https://www.skptricks.com/2018/06/append-or-prepend-html-using-reactjs.html
//
//
Comment <React.StrictMode> in index.js
After fetch console.log in React component like this:
Before return getting {} and {data} after fetch...
Pass empty function to onClick as temporary solution:
//
Cannot read properties of undefined (reading 'length'):
https://bobbyhadz.com/blog/javascript-cannot-read-property-length-of-undefined
In React console.log after fetch like this:
https://leocode.com/development/how-to-deal-with-async-await-in-the-array-functions/
https://bobbyhadz.com/blog/react-redirect-to-external-url
https://stackoverflow.com/questions/42914666/react-router-external-link
https://stackoverflow.com/questions/71333662/external-link-not-working-when-using-link-from-react-router-dom
https://stackoverflow.com/questions/66905176/how-to-redirect-to-external-url-onclick-in-react
https://stackoverflow.com/questions/47447441/cant-open-new-tab-in-react-adds-localhost3000-on-link
https://www.kindacode.com/article/ways-to-open-an-external-link-in-react/
https://stackoverflow.com/questions/18476373/how-to-add-target-blank-to-javascript-window-location
window.open - open link in a new window
window.location - open link in current window
https://bobbyhadz.com/blog/react-import-variable-from-another-file
https://stackoverflow.com/questions/38467574/import-javascript-file-and-call-functions-using-webpack-es6-reactjs
https://stackoverflow.com/questions/38467574/import-javascript-file-and-call-functions-using-webpack-es6-reactjs
Extract array from nested object by destructuring:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
https://www.w3schools.com/react/react_es6_destructuring.asp
https://blog.bitsrc.io/getting-nested-value-by-using-javascript-7828f7768cc7
https://stackoverflow.com/questions/909003/getting-the-first-index-of-an-object
https://dmitripavlutin.com/javascript-object-destructuring/
https://www.deadcoderising.com/2017-03-28-es6-destructuring-an-elegant-way-of-extracting-data-from-arrays-and-objects-in-javascript/
https://itnext.io/using-es6-to-destructure-nested-objects-in-javascript-avoid-undefined-errors-that-break-your-code-612ae67913e9
How to access public files in React and fetch JSON data from local file:
http://localhost:3000/data.json // JSON located in /ReactProject/public/data.json
https://akhtarvahid.medium.com/how-to-access-fetch-the-local-json-file-to-react-5ce07c43731d
import { useEffect, useState } from 'react';
https://www.codementor.io/@mohammedelhossinyriaad/how-the-useeffect-react-hook-work-1cq3g0g8bd
https://www.smashingmagazine.com/2020/07/custom-react-hook-fetch-cache-data/
https://www.robinwieruch.de/react-hooks-fetch-data/
https://dev.to/shaedrizwan/building-custom-hooks-in-react-to-fetch-data-4ig6
https://www.developerway.com/posts/how-to-fetch-data-in-react
https://use-http.com/#/
Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
// Try to use firstChild etc when selecting element =>
document.querySelector('main').lastChild.innerHTML;
//
https://javascript.info/json
https://learn.javascript.ru/fetch
https://blog.logrocket.com/modern-api-data-fetching-methods-react/
https://stackoverflow.com/questions/39019094/reactjs-get-json-object-data-from-an-url
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
https://stackoverflow.com/questions/33237200/fetch-response-json-gives-responsedata-undefined
https://stackoverflow.com/questions/51619534/fetch-data-from-mongoose-and-put-into-an-array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
https://stackoverflow.com/questions/64611880/how-to-fetch-an-array-object-from-api-json-file
https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call
https://stackoverflow.com/questions/37533929/how-to-return-data-from-promise
https://www.digitalocean.com/community/tutorials/how-to-use-the-javascript-fetch-api-to-get-data
https://stackoverflow.com/questions/60791658/value-undefined-returned-from-fetch-promise
https://stackoverflow.com/questions/12460378/how-to-get-json-from-url-in-javascript
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
https://stackoverflow.com/questions/66655216/why-is-my-response-data-undefined-when-sending-a-fetch
https://stackoverflow.com/questions/72217657/fetch-json-data-from-url-and-write-in-a-file
https://www.freecodecamp.org/news/json-stringify-example-how-to-parse-a-json-object-with-javascript/
https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe
cat /etc/hosts
http://localhost:3001/ === http://127.0.0.1:3001/
run react and node servers in parallel on UNIX => & as separator in react-app/package.json
npm init -y // if install new empty project
npm i dotenv // in existing project
npm i express // in existing project
sudo npm i nodemon -g // automatically restarts node server after change
npm list -g // global install === -g
/usr/local/lib
├── eslint@8.22.0
├── live-server@1.2.2
├── node-sass@7.0.1
├── nodemon@2.0.20
└── npm-run-all@4.1.5
https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel
https://towardsdev.com/how-to-set-up-a-node-js-express-server-for-react-c19104568d12
https://www.freecodecamp.org/news/how-to-create-a-react-app-with-a-node-backend-the-complete-guide/
https://www.geeksforgeeks.org/how-to-connect-node-js-with-react-js/
// search-box.jsx
// is same as above but worse in terms of code
// App.js
//
You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.
// change to defaultValue=''
Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function. Parameters are initialized to the values of the arguments supplied.
If parameter is function (clickHandler in this case), pass argument as function => clickHandler();
// to avoid message error clickHandler, pass empty function as onClick in necessary components
https://blog.openreplay.com/3-ways-of-passing-multiple-parameters-to-the-onclick-handler-in-react
https://stackoverflow.com/questions/26069238/call-multiple-functions-onclick-reactjs