Giter VIP home page Giter VIP logo

minesweeper's Issues

Update deps and fix types

Igal Kleiner comment:

In React 18 the FunctionComponent interface was changed and the implicit 'children' prop was omitted. You can find the reason here. Now you have to include the 'children' type by yourself. So here's the full solution. That will fix the "Property 'children' does not exist on type {}" error:

import { FC, PropsWithChildren } from 'react'
  
 // ...rest of the code
  
 interface HeaderProps {
   logo: string
 }
  
 interface LinkProps {
   href: string
   target?: '_blank' | '_self' | '_parent' | '_top'
   rel?: string
 }
  
 const Header: FC<PropsWithChildren<HeaderProps>> = ({ children, logo }) => (
   <header className='App-header'>
     <img src={logo} className='App-logo' alt='logo' />
     {children}
   </header>
 )
  
 const Link: FC<PropsWithChildren<LinkProps>> = ({ children, href, target = '_blank', rel = 'noopener noreferrer' }) => {
   return (
     <a className='App-link' href={href} target={target} rel={rel}>
       {children}
     </a>
   )
 }

Notice that 'PropsWithChildren' import. If, for example, you only want to use the 'children' prop, without passing any other prop, then you can use it without stating the props type for PropsWithChildren, ie:

const MyComponent: FC<PropsWithChildren> = ({ children }) => <div>{ children }</div>

Cheers!

Webpack 5 asset modules

Igal Kleiner:

Note about Webpack 5

As of Webpack 5, there's no need to install url-loader. Webpack 5 ships with Asset Modules, which replace url-loader, raw-loader and file-loader by adding 4 new module types - asset/resource, asset/inline, asset/source and asset. In my case, I wanted to copy all assets to the assets folder, so this was my configuration:

module.exports = {
      output: {
        // ...other output configurations
        assetModuleFilename: 'assets/[hash][ext][query]',
      },
      module: {
        rules: [
          // ...other rules,
          {
            test: /\.(png|jpg|gif|svg)$/i,
            type: 'asset/resource',
          },
        ],
      },
    }

And, of course, you can test it for .svg only:

test: /\.svg/,

Perhaps someone will find it helpful!

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.