Skip to content

Instantly share code, notes, and snippets.

@theodorosploumis
Last active December 3, 2022 10:25
Show Gist options
  • Save theodorosploumis/9cdd82f05c5ae444a5449f93a3733cbf to your computer and use it in GitHub Desktop.
Save theodorosploumis/9cdd82f05c5ae444a5449f93a3733cbf to your computer and use it in GitHub Desktop.
First steps in React JS. A list of resources to study on before starting with React.

There is always an enaqx/awesome-react for reference!

JS basics

React Basics

React Hooks - learn

React Hooks - collections

React Patterns

React Cheatsheets

React Best Practices

React props

Rendering methods

@theodorosploumis
Copy link
Author

theodorosploumis commented Mar 21, 2022

NextJS + JS important notes (Next 12.x)

  • Frequently used imports are moved into the main JavaScript bundle if they are used in at least half of the site pages.
  • Dynamic routes (/pages/blog/[id].js). Once we have the router object, we can extract information from it (const router = useRouter()). In particular we can get the dynamic part of the URL in the file by accessing router.query.id. The dynamic part can also just be a portion of the URL, like /pages/blog/post-[id].js.
  • As soon as an element wrapped within <Link> appears in the viewport (which means it's visible to the website user), Next.js prefetches the URL it points to (Production mode only).
  • Any links above the fold, at page load, start the prefetching as soon as the load event has been fired on your page (triggered when the page is fully loaded, and happens after the DOMContentLoaded event).
  • Since this is the client side router (const router = useRouter()), methods should only be used in
    frontend facing code. The easiest way to ensure this is to wrap calls in the useEffect() React hook.
  • JS: Calling APIs, downloading files, and reading files need async functions.

@theodorosploumis
Copy link
Author

theodorosploumis commented Mar 23, 2022

Debug (Drupal) page on NextJS

  • router.query.id (assuming the path is like /pages/[id].js. Get it const {id}= router.query)
  • pathName
  • drupal.node.nid
  • drupal.node.path_alias
  • drupal.node.uuid
  • Get data value from JSON (Chrome plugin)
  • UI to debug JSON API queries (VSCode extension)
  • render stats
  • page size
  • page web-vitals stats
  • invalidate time (NextJS)
  • context available
  • Environment indicator (dev, test, production etc)
  • Link to get JSON API request
  • Link to edit Drupal node
  • React Hook useDebugValue

@theodorosploumis
Copy link
Author

theodorosploumis commented Mar 23, 2022

Elements information

  • Name/Label
  • Description
  • Type (Component/Utility/Layout etc)
  • Data source
  • Data type (static/dynamic)
  • Re-validate/cache info
  • Lazy load, dynamic import
  • Has Variations
  • Hydration
  • Paths available (visibility)
  • Rendering
  • Stateless/Pure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment