Category: React

  • Innovative Planning 4: Manage Projects Successfully

    Innovative Planning 4: Manage Projects Successfully

    I’ve just completed a Toastmasters speech on my level 4 project in the Pathway project: Manage Projects Successfully

    I’ve reported to my club on the current project status. I have that currently conveyed from the following handout:

    Speech Handout on 20190702
    Project: Responsive Website

    During my speech, I’ve covered the following:

    • Project Phases
    • Software Engineers involved.
    • Theme template that will be used with the project.

    I received positive feedback. There are some additional items I need to work on (such as ensuring that everyone understands the technical aspects of the project). I will be incorporating this in future speeches.

    For full information about this project, please visit the project status page.

  • Developing Creating Communicators Gatsby Website

    Developing Creating Communicators Gatsby Website

    About the Project

    We’ve kick-started our programming for Toastmasters Creating Communicator’s new website! We’re developing the new website using GatsbyJS, a static site generator using React.

    Duane, Gabe, Derrick at Veranda on 20190630
    Meetup at Veranda, Concord on 2019-06-30

    Thank you to the following Software Engineers for helping our Toastmasters club enhance our current website.

    Toastmasters Presentation of the Project

    When: Tuesday, July 2
    Location: 4501 Deer Valley Rd. Antioch, CA 94531
    Room: Kaiser Permanente, Conference Room 1B or 1C

    I will be doing a Toastmaster’s presentation on the project timeline and information on all who are involved in this project. Please visit Toastmasters Creating Communicator’s current homepage for details on location.

    Project Timeline

    The phases are divided by 4 project phases:

    20190702 Project Timeframe

    I’ll describe what each phases entail:

    1. Training & Coordination: Our software engineers will be getting up to speed with GatsbyJS.
    2. R&D Phase: We’ll be doing the actual programming in this phase and integrating all components together.
    3. Test Phase: Club members will be testing the newly developed application.
    4. Deployment: Once club members have submitted their feedback and all software bugs have been fixed, our DevOps Engineer will deploy the website and make it live.

    Project Updates

    As part of this project on my Toastmasters project, I need to also create project status reports in the form of blogs. Listed on the following are status updates pertaining to this project:

    Project Links

  • React HashRouter

    React HashRouter

    Example code snippet on HashRouter from react-router-dom.  This routing alternative can be used on hosting services such as GitHub pages and other static hosting services.

    Implementation

    Import HashRouter:

    
    
    import { HashRouter as Router, Route } from 'react-router-dom';

    Example code that goes in render():

    
    
    <HashRouter>
       <div>
          <Route path="/" component={Home} />
          <Route path="about" component={About} />
          <Route path="teachers" component={Teachers} />
          <Route path="courses" component={Courses} />
       </div>
    </HashRouter>

    Here’s a link to my Gist if that doesn’t come out correctly.

    Drawbacks

    A collection of thoughts and issues I’ve found for using HashTag for a website:

    • There could be SEO issues related to using the HashTag URLS.
    • Clean URLs are better for SEO.  However, that’s also still questionable since this is a Single Page Application (SPA) unless generated from a NodeJS backend that can help generate the appropriate content.
  • Notes on React & ES6

    There are two modes for development: Single Page Applications, Multi Page Applications

    Build Workflow

    1. Dependency Management Tool: npm or yarn
    2. Use Bundler: Webpack
    3. Compiler: Babel + Presets
    4. Use Development Server (Docker preferrably)

    Single Page Applications (SPA)

    For React 16, I like to scaffold a new project using the create-react-app CLI:

    npm install -g create-react-app

    Multiple Page Applications (MPA)

    ES6 Basics

    Functions

    // Alternative function declaration.
    const myFunction = (someVar, anotherVar) => { return console.log(somevar + " and " + anotherVar); }
    
    // Removing brackets and return keyword.
    const myFunction = (someVar, anotherVar) => console.log(somevar + " and " + anotherVar);
    

    Exports & Imports (Modules)

    Export example from JSON object.

    // person.js
    const person = {
        name: "Duane"
    }
    
    export default person;
    
    // utility.js
    export const clean = () => {}
    export const baseData = 10;

    Import example of the above class.

    // Example 1
    import person from "./person.js";
    import prs from "./person.js";
    
    // Example 2
    import { baseData } from "./utility.js";
    import { clean } from "./utility.js";

    From lecture:

    Exports and Imports

    Spread & Rest Operators

    Spread Operator: …

    Yes, three dots 🙂

    // Spread
    // Used to spread out array elements or object properties.
    const newArray = [...oldArray, 1, 2];
    const newObject = {...oldObject, newProp: 5}
    
    // Rest
    // Used to merge a list of function arguments into an array.
    function sortArgs(...args) {
        return args.sort();
    }

    Destructing

    Easily extract array elements or object properties and store them in variables.

    // Array Destructing
    [a, b] = ["Duane", "Leem"];
    console.log(a); // Duane
    console.log(b); // Leem
    
    // Object Destructing
    {name} = {name: "Duane", age: 37}
    console.log(name); // Duane
    console.log(age); // 37

    Reference and Primitive Types

    Object and arrays are reference types. This is stored in memory (a pointer to the memory).

    As shown below, I’ve updated firstPerson but console.log secondPerson.  Noticed firstPerson is also “Mario”?  This is because Objects and Arrays are pointed to the same variable in your computer’s memory.

    const firstPerson = {
        name: "Duane "
    }
    
    const secondPerson = firstPerson ;
    firstPerson.name = "Mario";
    console.log(secondPerson); // Mario

    Array Functions

    const numbers = [1, 2, 3];
    
    // Using .map returns a new array.
    const doubleNumArray = numbers.map((num) => {
        return num * 2;
    });
    
    console.log(numbers); // [1, 2, 3]
    console.log(doubleNumArray); // [2, 4, 6]

    The original numbers were unchanged and the new array is actually new.

     

    React Basics

    Creating Components

    There are two ways to create components: Functional or Class

    Best practices is to use Functional Components.  Personally, I prefer Class Components but in the end it depends if your components are stateless or stateful.

    Functional Components

    const cmp = () => { 
        return

     

     

    Class Components

    class Cmp extends Component {
        render () {
            return

     

     

    Props & State

    Changes to props/state triggers React to re-render components and potentially updates to DOM.

    Props

    Props allow you to pass data from a parent (wrapping) component to a child (embedded) component.

    // Parent Component
    const posts = () => {
        return (
            <Post title="My first Post" />
        );
    }
    
    // Child Component
    const posts = (props) => { 
        return (
            <h1>{props.title}</h1>
        );
    }

    We’re passing the title from the parent/wrapping component call back to the child component.

    State

    Changes to State also triggers the component UI render automatically.

    class NewPost extends Component { 
        // state can only be accessed in class-based components!
        state = {
            counter: 1
        }; 
     
        // Needs to be implemented in class-based components! Needs to return some JSX!
        render() { 
            return (
                <h1>{this.state.counter}</h1>
            );
        }
    }
    

    Excerpt from course:

    Here, the NewPost component contains state. Only class-based components can define and use state. You can of course pass the state down to functional components, but these then can’t directly edit it.

    state simply is a property of the component class, you have to call it state though – the name is not optional. You can then access it via this.state in your class JSX code (which you return in the required render()  method).

    Whenever state changes (taught over the next lectures), the component will re-render and reflect the new state. The difference to props is, that this happens within one and the same component – you don’t receive new data (props ) from outside

    Sources: Supported Events

    Sources