Skip to content

React Development Repository for the Useful Coin LLC Website

Notifications You must be signed in to change notification settings

usefulcoin/react-www-development

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Development Guide

  1. Setup SSH keys. ssh-keygen -t ed25519 -C "[email protected]"
  2. Clone the repository. git clone [email protected]:usefulcoin/react-www-development.git
  3. Download necessary code. sudo apt -y update
  4. Make react-www-development the working directory. cd react-www-development
  5. Install node modules. npm i
  6. Run deploy script (from packages.json file). npm run build
  7. Push the build to the gh-pages subtree 'docs/' refer to Cobyism's Gist for detailed instructions.

Or run bash setup.bash && bash deploy.bash after steps 0, 1, and 3.

Read this for help with setting up SSH keys.

Learnings

The key learning was acquiring the knowledge to call in the index.html file. The key to this was employing the useEffect React hook to call the function after browser layout and paint. Read more here as it is the source of knowledge.

1. Running Medium Widget Scripts

Medium provides us a widget to retrieve articles from publication. It is put in script tags and added to the index.html file in the public directory of a React app.

For the initial build of this app, the script was:

<script type="text/javascript">

  function mediumWidget() {
    MediumWidget.Init({
      renderTo: "#medium-widget",
      params: {
        resource: "https://medium.com/usefulcoin",
        postsPerLine: 1,
        limit: 2,
        picture: "big",
        fields: ["description", "author", "claps", "publishAt"],
        ratio: "landscape"
      }
    })
  }

</script>

React has lifecycles for components. The top three are, essentially:

  1. componentDidMount (method executed after component mount)
  2. componentDidUpdate (method executed after component update)
  3. componentWillUnmount (method executed before component unmount)

To execute some function after (in this case) the Blog component mounts, we can use a React hook. In particular, the useEffect hook (or useLayoutEffect if you want to execute the method before painting) to manipulate the DOM after layout and paint in a "deferred event". Biggup to Trent Yang for ELI5 to me.

useEffect

Takes two arguments:

  1. A callback (fired after layout and paint so that it is non-blocking).
  2. An array (usually props).

Three options for method execution:

  1. useEffect( () => window.mediumWidget(), [...] ); triggered by changes to values in the array
  2. useEffect( () => window.mediumWidget() ); triggered by every render
  3. useEffect( () => window.mediumWidget(), [] ); triggered once like componentDidMount

2. Use CSS More

It's just cleaner to add lines to the end of a CSS styling section. For example, add this to the images section:

  .image #talent {
		max-width: 150;
	}

3. Standard React Stuff

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

npm run eject

Note: this is a one-way operation. Once you eject, you can’t go back!

If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

npm run build fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

About

React Development Repository for the Useful Coin LLC Website

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published