Media Query Container Component for React with no extra DOM nodes

Media query container component for React, with no extra DOM nodes!

Introduction

The goal of react-domless-media is to provide DOM-transparent javascript media query container for react.js. It is not creating any DOM nodes on its own, thus it does not disturb already existing styling.

How does it work?

a) All components provided as match would be rendered if provided conditions would be met.

b) All components provided as mismatch would be rendered if provided conditions would not be met.

What can be passed as component props?

React-domless-media accepts statically or dynamically generated single or multiple react components or react fragments as props.

Installation

npm i react-domless-media

Usage

React-domless-media is exporting higher order component as default export so no build-tools are required. In order to work, it requires custom javascript object hereinafter referred to as media query object to be passed first to the instance of this higher order component. You can use single or multiple media query objects (each should be provided to individual RDM HoC instance) in case of complex projects involving usage of many react apps simltaneously.

Media query object

Media quey object must consists of string key - object pairs. Each sub-object must consist of at least one (min or max) property paired with value of desired resolution stored as number. Below are the examples of proper media query objects.

Min is the direct equivalent of css min-width and it works as >= and max is the direct equivalent of max-width and it works as <=

const mediaQueries = {
	LARGE: { min: 1024 },
	MEDIUM: { max: 1023 },
	SMALL: { max: 700 },
	MICRO: { max: 400 }
}
const mediaQueries = {
	MID: {
		min: 500,
		max: 900
	}
}

Instantiating react-domless-media

The best practice is to create new .js file with all needed react-domless-media instances and export them.

Single-instance

import domlessMedia from 'react-domless-media'

const mediaQueries = {
	LARGE: { min: 1024 },
	MEDIUM: { max: 1023 },
	SMALL: { max: 700 },
	MICRO: { max: 400 }
}

const DOMLessMedia = domlessMedia(mediaQueries)
export default DOMLessMedia

Multiple instances

import domlessMedia from 'react-domless-media'

const mediaQueries = {
	LARGE: { min: 1024 },
	MEDIUM: { max: 1023 },
	SMALL: { max: 700 },
	MICRO: { max: 400 }
}

const mediaQueries2 = {
	MID: {
		min: 500,
		max: 900
	}
}

export const DOMLessMedia = domlessMedia(mediaQueries)
export const DOMLessMedia2 = domlessMedia(mediaQueries2)

Using in application

In order to select adequate media query, you must provide it as media prop. It must be the exact name of the key of given media property from media queries object of that particular instance. You must provide at least one react component as either match or mismatch prop, examples below. Remember to wrap multiple components in React.Fragment!

import DOMLessMedia from './DOMLessMedia.js'

<DOMLessMedia
	media={'LARGE'}
	match={<DesktopMenu menuItems={menuItems} />}
/>

In the example above, DesktopMenu component would be displayed only when window.innerWidth would be greater than or equal to a 1024 (pixels).

import DOMLessMedia from './DOMLessMedia.js'

<DOMLessMedia
	media={'MICRO'}
	match={<LogotypeSmall />}
	mismatch={<LogotypeBig />}
/>

In the example above, LogotypeSmall component would be displayed only when window.innerWidth would be less than or equal to a 400 (pixels), otherwise LogotypeBig would be displayed.

import DOMLessMedia2 from './DOMLessMedia2.js'

<DOMLessMedia
	media={'MID'}
	match={<LoginDesktop />}
/>

In the example above, LoginDesktop component would be displayed only when window.innerWidth would be greater than or equal to a 500 (pixels) and less than or equal to a 900 (pixels).

import DOMLessMedia from './DOMLessMedia.js'

<DOMLessMedia
	media={'MICRO'}
	match={
		<React.Fragment>
			<DesktopMenu menuItems={menuItems} />
			<SearchDesktop />
			<LoginDesktop />
		</React.Fragment>
		}
/>

In the example above, all children of DOMLessMedia component would be displayed only when window.innerWidth would be greater than or equal to a 1024 (pixels). Remember to wrap multiple components in React.Fragment!

Download Details:

Author: audiomancer

GitHub: https://github.com/audiomancer/react-domless-media

#react #javascript #reactjs #query

What is GEEK

Buddha Community

Media Query Container Component for React with no extra DOM nodes
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

Raleigh  Hayes

Raleigh Hayes

1626922680

React Query Tutorial | React Query For Beginners

Hey everyone! Today’s video is a short tutorial for React Query, I’ve been using it for a few months now and it’s been great! Would definitely recommend checking it out.

Useful Links:
GitHub: https://github.com/redhwannacef/youtube/tree/master/react-query

#react query tutorial #react #query #react query

Media Query Container Component for React with no extra DOM nodes

Media query container component for React, with no extra DOM nodes!

Introduction

The goal of react-domless-media is to provide DOM-transparent javascript media query container for react.js. It is not creating any DOM nodes on its own, thus it does not disturb already existing styling.

How does it work?

a) All components provided as match would be rendered if provided conditions would be met.

b) All components provided as mismatch would be rendered if provided conditions would not be met.

What can be passed as component props?

React-domless-media accepts statically or dynamically generated single or multiple react components or react fragments as props.

Installation

npm i react-domless-media

Usage

React-domless-media is exporting higher order component as default export so no build-tools are required. In order to work, it requires custom javascript object hereinafter referred to as media query object to be passed first to the instance of this higher order component. You can use single or multiple media query objects (each should be provided to individual RDM HoC instance) in case of complex projects involving usage of many react apps simltaneously.

Media query object

Media quey object must consists of string key - object pairs. Each sub-object must consist of at least one (min or max) property paired with value of desired resolution stored as number. Below are the examples of proper media query objects.

Min is the direct equivalent of css min-width and it works as >= and max is the direct equivalent of max-width and it works as <=

const mediaQueries = {
	LARGE: { min: 1024 },
	MEDIUM: { max: 1023 },
	SMALL: { max: 700 },
	MICRO: { max: 400 }
}
const mediaQueries = {
	MID: {
		min: 500,
		max: 900
	}
}

Instantiating react-domless-media

The best practice is to create new .js file with all needed react-domless-media instances and export them.

Single-instance

import domlessMedia from 'react-domless-media'

const mediaQueries = {
	LARGE: { min: 1024 },
	MEDIUM: { max: 1023 },
	SMALL: { max: 700 },
	MICRO: { max: 400 }
}

const DOMLessMedia = domlessMedia(mediaQueries)
export default DOMLessMedia

Multiple instances

import domlessMedia from 'react-domless-media'

const mediaQueries = {
	LARGE: { min: 1024 },
	MEDIUM: { max: 1023 },
	SMALL: { max: 700 },
	MICRO: { max: 400 }
}

const mediaQueries2 = {
	MID: {
		min: 500,
		max: 900
	}
}

export const DOMLessMedia = domlessMedia(mediaQueries)
export const DOMLessMedia2 = domlessMedia(mediaQueries2)

Using in application

In order to select adequate media query, you must provide it as media prop. It must be the exact name of the key of given media property from media queries object of that particular instance. You must provide at least one react component as either match or mismatch prop, examples below. Remember to wrap multiple components in React.Fragment!

import DOMLessMedia from './DOMLessMedia.js'

<DOMLessMedia
	media={'LARGE'}
	match={<DesktopMenu menuItems={menuItems} />}
/>

In the example above, DesktopMenu component would be displayed only when window.innerWidth would be greater than or equal to a 1024 (pixels).

import DOMLessMedia from './DOMLessMedia.js'

<DOMLessMedia
	media={'MICRO'}
	match={<LogotypeSmall />}
	mismatch={<LogotypeBig />}
/>

In the example above, LogotypeSmall component would be displayed only when window.innerWidth would be less than or equal to a 400 (pixels), otherwise LogotypeBig would be displayed.

import DOMLessMedia2 from './DOMLessMedia2.js'

<DOMLessMedia
	media={'MID'}
	match={<LoginDesktop />}
/>

In the example above, LoginDesktop component would be displayed only when window.innerWidth would be greater than or equal to a 500 (pixels) and less than or equal to a 900 (pixels).

import DOMLessMedia from './DOMLessMedia.js'

<DOMLessMedia
	media={'MICRO'}
	match={
		<React.Fragment>
			<DesktopMenu menuItems={menuItems} />
			<SearchDesktop />
			<LoginDesktop />
		</React.Fragment>
		}
/>

In the example above, all children of DOMLessMedia component would be displayed only when window.innerWidth would be greater than or equal to a 1024 (pixels). Remember to wrap multiple components in React.Fragment!

Download Details:

Author: audiomancer

GitHub: https://github.com/audiomancer/react-domless-media

#react #javascript #reactjs #query

Raleigh  Hayes

Raleigh Hayes

1626889860

React Query Mutations Tutorial

Hey everyone! In this week’s video, we are taking another look at React Query, specifically how to handle mutations. Hope you enjoy it!

Useful Links:
GitHub: https://github.com/redhwannacef/youtube/tree/master/react-query

#query #react #react query #react query tutorial

Anda Lacacima

Anda Lacacima

1594560120

How to Build React Component using React, React DOM and Babel

Now Let’s start discussing today’s topic.Today we’ll discuss about basic things you must know about React Library.It’s a famous front-end library which use in IT industry for business applications.Also day by day it’s getting updated.So, It will be much important for you to keep in touch with this library if you are willing/doing a_ job in IT industry _as it’s already a trending front-end technology now a days.So we’ll discuss it in details now and create your first React Component.

What is React ?

Simply, React is a JavaScript library that use to create _User Interfaces which runs on browsers _which was created by** Facebook._(one of the most popular ones, with over 100,000 stars on GitHub). It is the _view_ layer of an _MVC application**_ (Model View Controller)_

NOTE: React is not a framework.It’s a JavaScript library.

For a business application(client application) to be extremely successful it must be maintainable,manageable and_ re-usable.__Because when the business is expanding and when the customers asking for more improvement/changes the development team must be much responsible for making quick changes in the client application as soon as possible.That’s a more than 100% truth in _IT industry.So you must be a fast learner and a fast adapter when client requests rapid and complex changes in your business application.

Does React helps to overcome implementation complexity of client’s business applications

Yes.This is the most valuable and important thing which helps you when implementing a complex business application.React uses a concept called_ re-usable component__ which you may feel much comfortable with.It makes you re-use the same code in several places.Only thing you need to do is make changes to your props and __states.Using tiny components you could build your complex application in a simple way. __Also as this is a view part of the application it doesn’t depend(isolated with) on the _server state.

Components_ are like custom, reusable HTML elements, to quickly and efficiently build__ user interfaces_

_Now it’s time to try this with your own.I’m used _this online editor.It shows HTML, CSS, JavaScript sections clearly and separately.I recommend you to use it to make your first _React Component.

_We’ll create a simple HTML element which displays name and age of a __Person _using CSS styling as below(Image shows how a Person Component used to display information of two persons called Sanath and Pramod);

Image for post

person.figure

You only need both HTML,CSS files below to implement Person component using HTML and CSS.Use below code in editor to try this.

#components #react-dom #programming #react #babel