daily log 12.20.20

less than 1 minute read

TIL:

Reverse an array:

myArray.map((val, index, array) => array[array.length - 1 - index]);

Add key to react fragment

React drag and drop

Today, this error reactjs - Create-React-App build - "Uncaught SyntaxError: Unexpected token <" - Stack Overflow was caused by the homepage: line in package json. Solved by simply deleting that line.

REACT HEROKU EXPRESS PARTY

  1. yarn add express
  2. In the same directory as your package json, make a server/server.js
  3. Update package json start script from "start": "react-scripts start" (use this for dev still) to "start": "node server/server.js"
  4. Remove package json homepage field at the bottom "homepage": "https://aaroncaraway.github.io/umre-todo/"

SCRIPT.JS

const path = require('path');
const express = require('express');
const app = express();
const publicPath = path.join(__dirname, '../build');
const port = process.env.PORT || 5000;
app.use(express.static(publicPath));
app.get('*', (req, res) => {
   res.sendFile(path.join(publicPath, 'index.html'));
});
app.listen(port, () => {
   console.log('Server is up!');
});

To help me search for this next time

heroku react react heroku deploy react heroku heroku deploy react react on heroku