Month: January 2020

  • Using JSON data to populate a component

    Continuing from our last post, this is now our component code: We can access the JSON using this.props.data. We can then loop through the updates using “map” and add a new table row for each update and store it all up in the variable tableRows. We also use a function getLink() that renders different things…

  • Using JSON in React

    Sample JSON data: The data is sorted by year and each update has a name and type. To import this data into a component: Import the JSON by linking to it. Set a variable to contain all the data. We then want to pick out a certain year using “find”. Then we can use that…

  • Link to other pages in React

    First you will need react-router-dom. Install it using: Here is the code that directs you to each page: BrowserRouter is the container. Switch will find and render the first page that matches the path/url. Link to the pages using NavLinks:

  • Using state to toggle content visibility

    Here is the code: We set up the default state in the constructor and bind the on click function that toggles the state using the previous state. The bind makes “this” work in the function. Then the navigation’s class updates when the state changes.

  • Using SASS with React

    It sounds simple enough. Just run npm install node-sass and change your css file file to a scss. Well… it didn’t work for me. What I need to do was update my Create-React-App to Version 2. To do this, go to packages.json and change the “react-scripts” version to 2.0.3. Simple… when you know it. Thanks…

  • Fixing the auto font resizing on phones using Safari

    Safari on mobile will resize your fonts if it thinks it’s too small. This is probably related to accessibility but it doesn’t make sense to me and is annoying. Anyways to fix it add this Original post here.