Skip to main content

Posts

Showing posts from November, 2020

Resetting to initial State with React Hook

 Resetting to the initial state after form submission or cancelling a form submission is an integral part of the user experience when creating forms in ReactJS. This morning I was trying to find a way to reset the form I was working on. I found this to be the most effective way to reset a form // declaring the initial state const initialState = { fname: "", lname: "", email: ""} const [eachEntry, seteachEntry] = useState(initialState); const {fname, lname, email} = eachEntry ... // function to handle onSubmit event const handleSubmit = event => {     event.preventDefault();     axios.post('http://some.url/api', {          // some javascript object      }). then(() => {          event.target.reset();      } } return(     <div>          <form onSubmit={handleSubmit}>          // some form input ...

Using dotenv to hide credentials in ExpressJS

This is a quick tutorial on using dotenv in JavaScript Development When building apps, we continually need access to databases. To access those databases, we need to be authenticated to be authorized to access the resources stored. In Web Development/app building, especially when storing code in a publicly accessible repository like GitHub, we should be conscious of our credentials. The way to get around storing your code on without credentials on GitHub is by using dotenv. dotenv is a JavaScript package that enables users to and access credentials safely. In your server.js file, add the following code const express = require(“express”); const app = express(); const dotenv = require('dotenv') ... dotenv.config() ... const password = process.env.[variable_name] ... app.listen(3000, () => console.log(“server has started at port 3000”)); In the home directory, create a .env file. In the .env file create the variable name referenced in the using the following format. varia...

Web Development

For the past three months, I've been part of the Pacifica Prime BootCamp run by SwitchMaven. During my time there, I've learnt a lot about Web Development. I would like to think I'm a Full-Stack Web Developer but I have a lot to learn still. We've learnt about: HTML, CSS, JavaScript, Express JS and React JS. I will be putting out articles about those topics as I get more confident with each topic. There's so much to learn and I hope this can be a good resource for some.