- Setup SSH keys.
ssh-keygen -t ed25519 -C "[email protected]"
- Clone the repository.
git clone [email protected]:usefulcoin/react-www-development.git
- Download necessary code.
sudo apt -y update
- Make react-www-development the working directory.
cd react-www-development
- Install node modules.
npm i
- Run deploy script (from packages.json file).
npm run build
- 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.
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.
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:
- componentDidMount (method executed after component mount)
- componentDidUpdate (method executed after component update)
- 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.
Takes two arguments:
- A callback (fired after layout and paint so that it is non-blocking).
- An array (usually props).
Three options for method execution:
- useEffect( () => window.mediumWidget(), [...] ); triggered by changes to values in the array
- useEffect( () => window.mediumWidget() ); triggered by every render
- useEffect( () => window.mediumWidget(), [] ); triggered once like componentDidMount
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;
}
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.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
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.
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.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify