• Home
  • Privacy Policy
Breaking News, US News, World News and Bollywood News
  • Home
  • Technology
    What is JPA? Introduction to the Jakarta Persistence API

    What is JPA? Introduction to the Jakarta Persistence API

    Understand the trade-offs with reactive and proactive cloudops

    Understand the trade-offs with reactive and proactive cloudops

    Google Cloud launches services to bolster open-source security, simplify zero-trust rollouts

    Google Cloud boosts open-source security, simplifies zero-trust rollouts

    Java concurrency could be about to get easier

    Java concurrency could be about to get easier

    OpenFeature feature flag project applies for CNCF sandbox project status

    OpenFeature feature flag project applies for CNCF sandbox project status

    Developer survey: JavaScript and Python reign, but Rust is rising

    Developer survey: JavaScript and Python reign, but Rust is rising

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Entertainment
    John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

    John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

    Remember HeroQuest? The classic board game from the 80s and 90s is BACK | Gaming | Entertainment

    Remember HeroQuest? The classic board game from the 80s and 90s is BACK | Gaming | Entertainment

    Platinum Jubilee puzzle: Like Where’s Wally with dogs – can you spot the Corgi? | Gaming | Entertainment

    Platinum Jubilee puzzle: Like Where’s Wally with dogs – can you spot the Corgi? | Gaming | Entertainment

    Wordle 336 May 21 HINTS – Struggling with today’s Wordle? Three CLUES to help with answer | Gaming | Entertainment

    Wordle 336 May 21 HINTS – Struggling with today’s Wordle? Three CLUES to help with answer | Gaming | Entertainment

    Pirates of the Caribbean’s production was helped by The Goonies | Films | Entertainment

    Pirates of the Caribbean’s production was helped by The Goonies | Films | Entertainment

    Got this rare PS4 game? It’s now worth more than PS5 or Xbox Series X | Gaming | Entertainment

    Got this rare PS4 game? It’s now worth more than PS5 or Xbox Series X | Gaming | Entertainment

    Trending Tags

      • Bollywood
      • Hollywood
      • Music
    • Lifestyle
      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      Chelsea Flower Show: When is it, how to get tickets and which royals could attend

      Chelsea Flower Show: When is it, how to get tickets and which royals could attend

      Monty Don shares warning as his tulips suffer disease – symptoms to look for

      Monty Don shares warning as his tulips suffer disease – symptoms to look for

      Pests: Protect your garden from slugs using fruit leftovers – ‘natural deterrent’

      Pests: Protect your garden from slugs using fruit leftovers – ‘natural deterrent’

      Garden pests: Always use the ‘four P’s’ to stop pests ‘wreaking havoc’ in gardens

      Garden pests: Always use the ‘four P’s’ to stop pests ‘wreaking havoc’ in gardens

      Carol Klein: ‘Important’ step when sowing cucumber seeds to ensure a ‘bumper harvest’

      Carol Klein: ‘Important’ step when sowing cucumber seeds to ensure a ‘bumper harvest’

      Trending Tags

      • Golden Globes
      • Game of Thrones
      • MotoGP 2017
      • eSports
      • Fashion Week
    • Nature
    • Business
    • Health
      • Food
    • Fashion
    • Science
    • Sports
    • Travel
    • World News
    No Result
    View All Result
    • Home
    • Technology
      What is JPA? Introduction to the Jakarta Persistence API

      What is JPA? Introduction to the Jakarta Persistence API

      Understand the trade-offs with reactive and proactive cloudops

      Understand the trade-offs with reactive and proactive cloudops

      Google Cloud launches services to bolster open-source security, simplify zero-trust rollouts

      Google Cloud boosts open-source security, simplifies zero-trust rollouts

      Java concurrency could be about to get easier

      Java concurrency could be about to get easier

      OpenFeature feature flag project applies for CNCF sandbox project status

      OpenFeature feature flag project applies for CNCF sandbox project status

      Developer survey: JavaScript and Python reign, but Rust is rising

      Developer survey: JavaScript and Python reign, but Rust is rising

      Trending Tags

      • Nintendo Switch
      • CES 2017
      • Playstation 4 Pro
      • Mark Zuckerberg
    • Entertainment
      John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

      John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

      Remember HeroQuest? The classic board game from the 80s and 90s is BACK | Gaming | Entertainment

      Remember HeroQuest? The classic board game from the 80s and 90s is BACK | Gaming | Entertainment

      Platinum Jubilee puzzle: Like Where’s Wally with dogs – can you spot the Corgi? | Gaming | Entertainment

      Platinum Jubilee puzzle: Like Where’s Wally with dogs – can you spot the Corgi? | Gaming | Entertainment

      Wordle 336 May 21 HINTS – Struggling with today’s Wordle? Three CLUES to help with answer | Gaming | Entertainment

      Wordle 336 May 21 HINTS – Struggling with today’s Wordle? Three CLUES to help with answer | Gaming | Entertainment

      Pirates of the Caribbean’s production was helped by The Goonies | Films | Entertainment

      Pirates of the Caribbean’s production was helped by The Goonies | Films | Entertainment

      Got this rare PS4 game? It’s now worth more than PS5 or Xbox Series X | Gaming | Entertainment

      Got this rare PS4 game? It’s now worth more than PS5 or Xbox Series X | Gaming | Entertainment

      Trending Tags

        • Bollywood
        • Hollywood
        • Music
      • Lifestyle
        ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

        ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

        Chelsea Flower Show: When is it, how to get tickets and which royals could attend

        Chelsea Flower Show: When is it, how to get tickets and which royals could attend

        Monty Don shares warning as his tulips suffer disease – symptoms to look for

        Monty Don shares warning as his tulips suffer disease – symptoms to look for

        Pests: Protect your garden from slugs using fruit leftovers – ‘natural deterrent’

        Pests: Protect your garden from slugs using fruit leftovers – ‘natural deterrent’

        Garden pests: Always use the ‘four P’s’ to stop pests ‘wreaking havoc’ in gardens

        Garden pests: Always use the ‘four P’s’ to stop pests ‘wreaking havoc’ in gardens

        Carol Klein: ‘Important’ step when sowing cucumber seeds to ensure a ‘bumper harvest’

        Carol Klein: ‘Important’ step when sowing cucumber seeds to ensure a ‘bumper harvest’

        Trending Tags

        • Golden Globes
        • Game of Thrones
        • MotoGP 2017
        • eSports
        • Fashion Week
      • Nature
      • Business
      • Health
        • Food
      • Fashion
      • Science
      • Sports
      • Travel
      • World News
      No Result
      View All Result
      Updates News
      No Result
      View All Result
      Home Technology

      Hands-on with GatsbyJS | InfoWorld

      admin by admin
      January 13, 2022
      in Technology
      0
      Hands-on with GatsbyJS | InfoWorld
      0
      SHARES
      7
      VIEWS
      Share on FacebookShare on Twitter


      Somewhere between using a WYSIWYG editor like Wix and building your own stack from the ground up with something like Webpack is using a framework like Gatsby.

      Gatsby is better known as a static site generator, though it also competes with full-blown full-stack, server-side rendering frameworks like Next.js and SvelteKit. Gatsby takes pains to make the development experience friendly and easy, while delivering essential website features like modern blur-up images out-of-the-box.

      But unlike Next.js or SvelteKit, Gatsby is purely a front-end framework, not a full-stack one. Therefore, Node.js is required for development, but not for deployment. For that, Gatsby supports several click-to-deploy platforms including Netlify and Gatsby Cloud.

      Let’s dive right in — it’s the best way to get a sense for how Gatsby works and what it offers. You’ll need access to a command line to a Node.js/NPM installation, as well as to Git, which is used to download the starter kit. Once you have access to NPM from the command line, use it to install Gatsby globally by typing npm install -g gatsby-cli.

      When that is complete, you should be able to type gatsby -v and get a response with the installed version. Start building a new app with gatsby new. Gatsby will largely hold your hand through the interactive process, and any choices you make can be changed later. I named my project “My Demo” and accepted the default location of my-demo.

      When prompted for which CMS to use, you can accept “No (or I’ll add it later)” as the response. Same goes for CSS processors. You can leave the choices blank for which additional plug-ins to add.

      Run the Gatsby starter app

      Now you can run the app in dev mode by cd-ing into the new directory (my-demo) and typing gatsby develop.

      Once that is running, you can visit localhost:8000 and see the welcome screen as in Figure 1.

      Figure 1. Gatsby welcome screen

      gatsbyjs new site IDG

      Hot module replacement

      Gatsby ships with HMR (hot module replacement) active, so go ahead and modify the <title> element in /src/pages/index.js to be <title>My Home Page></title> and you will immediately see this change reflected in the browser. (Be sure the app is running in dev mode; either background the process or open a new command-line window.)

      Add a page

      Gatsby is built on React, so you have the full range of React capabilities at your disposal. A key fact about developing in Gatsby is that each page is a React component. Even the index page is a React component. You can verify this by opening that file and observing that it defines a function (const IndexPage = () => { return (...)) and then exports it as a JS module (export default IndexPage). In short, the index.html file exports a React functional component that represents the index page.

      Let’s add a new page, and make it dead simple. Create a new file /src/pages/mypage.js and give it the contents of Listing 1.

      Listing 1. Adding a simple page

      import * as React from "react";
      const MyPage = () => {  return (
              My New Page
      )}
      export default MyPage;

      Adding navigation

      You can visit the new page at localhost:8000/mypage. Now add a link from your new page to the index page. Add Gatsby’s built-in Link component by importing it:

      import { Link } from 'gatsby'

      Now add it to your page with <Link to="https://www.infoworld.com/">Home</Link>. The link will appear and you can click it to navigate to the index page.

      Creating a shared component

      Now add a new file src/components/Dog.js. (Note you’re adding the components directory as well.) Put the contents of Listing 2 into this file.

      Listing 2. The Dog component

      cat src/components/Dog.js
      import * as React from "react";
      const DogComponent = ({ name }) => {
              return (
      {name} says Woof!
              )}     
      export default DogComponent;

      This is a typical reusable React component that accepts a single prop (name), which is then used in the markup via the token syntax. You can use it in the page components as seen in Listing 3.

      Listing 3. Using the Dog component

      import Dog from '../components/Dog.js';
      //...
      <Dog name="Buster" />

      There is nothing Gatsby-specific here, except for the fact that your shared components do not go in the pages directory. (Note there is nothing special about the name of the components directory.)

      Using images

      One of Gatsby’s claims to fame is its sophisticated image support. This is now delivered via official plug-ins. Let’s add images to the Dog component. Begin by installing the NPM packages as seen in Listing 4.

      Listing 4. Installing image plug-ins and dependencies

      npm install gatsby-plugin-image gatsby-plugin-sharp gatsby-source-filesystem gatsby-transformer-sharp

      Listing 4 installs four different plug-ins used by Gatsby for handling images and loading them from the file system. Now register the plug-ins with Gatsby by editing the gatsby-config.js file in the project root directory. That file has an empty plug-ins entry in the module export. Add the plug-in entries seen in Listing 5.

      Listing 5. Registering image plug-ins in gatsby-config.js

      plugins: [ `gatsby-plugin-image`, `gatsby-plugin-sharp` ]

      The two image plug-ins include one for dynamic images (images which are data driven, i.e., which can change depending on the app state) and one for static images, which remain always the same. In this case, we’re just going to use a static image.

      Open the /src/components/dog.js file and add the import and component as seen in Listing 6.

      Listing 6. Using the StaticImage component

      import * as React from "react";
      import { StaticImage } from "gatsby-plugin-image";

      const DogComponent = ({ name }) => {
              return (
                 <div>
                      Foo2
                      <div>
                      <StaticImage src="https://www.infoworld.com/article/3646408/https://dogtime.com/assets/uploads/gallery/shih-tzu-dog-breed-pictures/shih-tzu-breed-picture-1.jpg" alt="A Shitzu" width={350} height={350}/>
                      </div>
                      <span>{name} says Woof!</span>
                 </div>
              )}     
      export default DogComponent;

      Listing 6 imports the StaticImage component from the gatsby-plugin-image package and uses it to display the image at the given URL. Note that if you want to load files from the local file system, you’ll need to also import gatsby-source-filesystem and configure it to point to the location(s) where your image files reside (see here). If you want to use dynamic images, you use the GatsbyImage component, and you have to include the gatsby-transformer-sharp plug-in.

      Gatsby and GraphQL

      Another notable feature of Gatsby is its heavy use of GraphQL, which is a query language originated by Facebook. GraphQL can pull data from numerous sources for use by your components. This capability is used across many of Gatsby’s plug-ins to unify how data is loaded.

      I’m going to give you a sense of how this works by pulling out data from the information defined inside the gatsby-config.js file. A similar process is used for accessing files from the file system and data from content management systems and databases.

      First, look at gatsby-config.js. Notice it exports a couple of metadata fields, as seen in Listing 7.

      Listing 7. gatsby-config.js exports

      module.exports = {
        siteMetadata: {
          siteUrl: "https://www.yourdomain.tld",
          title: "My Demo",
        }

      Now open the src/pages/mypage.js file and access that metadata as shown in Listing 8.

      Listing 8. Accessing the metadata with GraphQL

      import * as React from "react";
      import { Link, useStaticQuery, graphql } from 'gatsby';
      import Dog from '../components/Dog.js';

      const MyPage = () => { 
      const data = useStaticQuery(graphql`
          query {
            site {
              siteMetadata {
                title
              }
            }
          }
        `)
      return (
              <main>{data.site.siteMetadata.title}
                <Link to="https://www.infoworld.com/">Home</Link>
              <br />
      <Dog name="Buster" />
              </main>
      )}

      export default MyPage;

      The changes in Listing 8 begin with importing the useStaticQuery and graphql packages from gatsby. In the body of the markup, you can see a token accessing the site metadata with {data.site.siteMetadata.title}. But where does this data come from?

      Before the return statement, the data variable is populated with a call to useStaticQuery, and this defines a GraphQL query that accesses the site metadata. These queries have access to page variables like query params, and thus can be fully dynamic when accessing the data store (i.e., using entity Ids).

      GraphQL is probably the biggest hurdle to adopting Gatsby, due to its complex-seeming interface. But in the long run, GraphQL provides a powerful approach to unified data querying.

      The Great Gatsby

      You’ve gotten a taste for some of Gatsby’s capabilities. Gatsby sports a vast plug-in ecosystem, with both official and community-created plug-ins. It’s a good place to start whenever you need something.

      Gatsby continues to evolve to keep pace with industry changes. It’s a tempting option, especially when looking to build static sites like blogs.

      Read more about JavaScript development

      Copyright © 2022 IDG Communications, Inc.



      Source link

      admin

      admin

      • Trending
      • Comments
      • Latest
      Plant warning as bamboo causes £100,000 of damage to Hampshire property

      Plant warning as bamboo causes £100,000 of damage to Hampshire property

      January 31, 2022
      Social workers warned weeks before baby Mitchell died in 2019 | TV & Radio | Showbiz & TV

      Social workers warned weeks before baby Mitchell died in 2019 | TV & Radio | Showbiz & TV

      January 2, 2022
      Yorkshire nan on how to make Yorkshire puddings with no ingredients weighed

      Yorkshire nan on how to make Yorkshire puddings with no ingredients weighed

      February 15, 2022
      Newcastle transfer news: Last-gasp offer made for Dele Alli in late Everton hijack attempt | Football | Sport

      Newcastle transfer news: Last-gasp offer made for Dele Alli in late Everton hijack attempt | Football | Sport

      January 31, 2022
      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      0
      Boris Johnson slammed by Indie band for using their song ‘Blue Bunch Of Corrupt W****rs’ | Music | Entertainment

      Boris Johnson slammed by Indie band for using their song ‘Blue Bunch Of Corrupt W****rs’ | Music | Entertainment

      0
      Call Your Mom, Because Sue Grafton’s Alphabet Murder Mystery Books Are Becoming A Show

      Call Your Mom, Because Sue Grafton’s Alphabet Murder Mystery Books Are Becoming A Show

      0
      Release Date, Cast, And More

      Release Date, Cast, And More

      0
      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      May 21, 2022
      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      May 21, 2022
      The Passion Of Joan Of Arc Is Potent As Ever

      The Passion Of Joan Of Arc Is Potent As Ever

      May 21, 2022
      John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

      John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

      May 21, 2022

      Recent News

      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      May 21, 2022
      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      May 21, 2022
      The Passion Of Joan Of Arc Is Potent As Ever

      The Passion Of Joan Of Arc Is Potent As Ever

      May 21, 2022
      John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

      John Wayne’s way to protect ‘man he loved more than anybody’ from humiliation | Films | Entertainment

      May 21, 2022
      Breaking News, US News, World News and Bollywood News

      Follow Us

      Browse by Category

      • Bollywood
      • Business
      • Entertainment
      • Fashion
      • Food
      • Health
      • Hollywood
      • Lifestyle
      • Music
      • Nature
      • Science
      • Sports
      • Technology
      • Travel
      • World News

      Recent News

      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      Ukraine warns EU ‘time is of the essence’ as bloc goes soft on sanctions: ‘Be bolder!’ | Science | News

      May 21, 2022
      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      ‘Best environment’ for growing sweet potatoes to ‘increase chances of a good crop’

      May 21, 2022
      • Home
      • Privacy Policy

      © 2021 Updates News

      No Result
      View All Result

      © 2021 Updates News