Wednesday, October 28, 2020

Study shows which gaming companies are using the influencer-marketing strategy the most

CreatorIQ, an influencer-marketing platform, analyzed thousands of sponsored posts from creators and influencers to discover which brands were appearing most in sponsored ads. CreatorIQ examined two thousand seven hundred posts from one hundred and eighty creators and influencers from last month...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Arooj Ahmed via Digital Information World

The Best Software for Live Streaming on YouTube

Back in 2016, researchers laid out a prediction that the Live Streaming industry would be worth $70 billion by 2021. Interestingly, they didn’t take into account the coronavirus outbreak, something that encouraged a considerable portion of the human population to resort to live streaming for the...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Ali Siddiqui via Digital Information World

During the year 2020, the rate of online shopping apps have increased by 40%

The coronavirus pandemic has locked everyone in their homes. People have no other things except for using social media and as all types of shopping malls are closed people are engaged in online shopping. They are shopping more than usual as they have no other source of entertainment and no other...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Arooj Ahmed via Digital Information World

Working with Forms in React

Working with Forms in React

Almost every application needs to accept user input at some point, and this is usually achieved with the venerable HTML form and its collection of input controls. If you’ve recently started learning React, you’ve probably arrived at the point where you’re now thinking, “So how do I work with forms?”

This article will walk you through the basics of using forms in React to allow users to add or edit information. We’ll look at two different ways of working with input controls and the pros and cons of each. We’ll also take a look at how to handle validation, and some third-party libraries for more advanced use cases.

Uncontrolled Inputs

The most basic way of working with forms in React is to use what are referred to as “uncontrolled” form inputs. What this means is that React doesn’t track the input’s state. HTML input elements naturally keep track of their own state as part of the DOM, and so when the form is submitted we have to read the values from the DOM elements themselves.

In order to do this, React allows us to create a “ref” (reference) to associate with an element, giving access to the underlying DOM node. Let’s see how to do this:

class SimpleForm extends React.Component {
  constructor(props) {
    super(props);
    // create a ref to store the DOM element
    this.nameEl = React.createRef();
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleSubmit(e) {
    e.preventDefault();
    alert(this.nameEl.current.value);
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>Name:
          <input type="text" ref={this.nameEl} />
        </label>
        <input type="submit" name="Submit" />
      </form>
    )
  }
}

As you can see above, for a class-based component you initialize a new ref in the constructor by calling React.createRef, assigning it to an instance property so it’s available for the lifetime of the component.

In order to associate the ref with an input, it’s passed to the element as the special ref attribute. Once this is done, the input’s underlying DOM node can be accessed via this.nameEl.current.

Let’s see how this looks in a functional component:

function SimpleForm(props) {
  const nameEl = React.useRef(null);

  const handleSubmit = e => {
    e.preventDefault();
    alert(nameEl.current.value);
  };

  return (
     <form onSubmit={handleSubmit}>
       <label>Name:
         <input type="text" ref={nameEl} />
       </label>
       <input type="submit" name="Submit" />
     </form>
   );
}

There’s not a lot of difference here, other than swapping out createRef for the useRef hook.

Example: login form

function LoginForm(props) {
  const nameEl = React.useRef(null);
  const passwordEl = React.useRef(null);
  const rememberMeEl = React.useRef(null);

  const handleSubmit = e => {
    e.preventDefault();

    const data = {
      username: nameEl.current.value,
      password: passwordEl.current.value,
      rememberMe: rememberMeEl.current.checked,
    }

    // Submit form details to login endpoint etc.
    // ...
  };

  return (
     <form onSubmit={handleSubmit}>
       <input type="text" placeholder="username" ref={nameEl} />
       <input type="password" placeholder="password" ref={passwordEl} />
       <label>
         <input type="checkbox" ref={rememberMeEl} />
         Remember me
       </label>
       <button type="submit" className="myButton">Login</button>
     </form>
   );
}

View on CodePen

While uncontrolled inputs work fine for quick and simple forms, they do have some drawbacks. As you might have noticed from the code above, we have to read the value from the input element whenever we want it. This means we can’t provide instant validation on the field as the user types, nor can we do things like enforce a custom input format, conditionally show or hide form elements, or disable/enable the submit button.

Fortunately, there’s a more sophisticated way to handle inputs in React.

Controlled Inputs

An input is said to be “controlled” when React is responsible for maintaining and setting its state. The state is kept in sync with the input’s value, meaning that changing the input will update the state, and updating the state will change the input.

Let’s see what that looks like with an example:

class ControlledInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = { name: '' };
    this.handleInput = this.handleInput.bind(this);
  }

  handleInput(event) {
    this.setState({
      name: event.target.value
    });
  }

  render() {
    return (
      <input type="text" value={this.state.name} onChange={this.handleInput} />
    );
  }
}

As you can see, we set up a kind of circular data flow: state to input value, on change event to state, and back again. This loop allows us a lot of control over the input, as we can react to changes to the value on the fly. Because of this, controlled inputs don’t suffer from the limitations of uncontrolled ones, opening up the follow possibilities:

  • instant input validation: we can give the user instant feedback without having to wait for them to submit the form (e.g. if their password is not complex enough)
  • instant input formatting: we can add proper separators to currency inputs, or grouping to phone numbers on the fly
  • conditionally disable form submission: we can enable the submit button after certain criteria are met (e.g. the user consented to the terms and conditions)
  • dynamically generate new inputs: we can add additional inputs to a form based on the user’s previous input (e.g. adding details of additional people on a hotel booking)

Validation

As I mentioned above, the continuous update loop of controlled components makes it possible to perform continuous validation on inputs as the user types. A handler attached to an input’s onChange event will be fired on every keystroke, allowing you to instantly validate or format the value.

Continue reading Working with Forms in React on SitePoint.


by Nilson Jacques via SitePoint

An ultimate guide to grid design

Frontend  Focus

#464 — October 28, 2020 | Read on the web

Responsive Grid Design: An Ultimate Guide — A comprehensive and highly visual guide to using grid for layout (think column structure, gutters, side margin values, etc). The sort of thing that's handy for reference.

Nitish Khagwal

A Primer on the Different Types of Browser Storage — The browser has many options we can utilize to store data, this post from Ido Shamun runs through them.

CSS-Tricks

New Course: Introduction to Next.js, The Full-Stack React Framework — Next.js is a complete framework built on top of React.js. You'll learn server-side rendering, static site generation, data fetching, code API endpoints, creating pages with the file system, add CSS modules, and more.

Frontend Masters sponsor

Prevent Layout Shifts with CSS Grid Stacks — A detailed explanation with real examples of a CSS grid technique used to prevent layout shifts when a component state changes.

Hubert Sablonnière

Faster Web App Delivery with PRPL — PRPL is a pattern for structuring and serving web applications and Progressive Web Apps with an emphasis on improved app delivery and launch performance.

Addy Osmani

⚡️ Quick bits:

💻 Jobs

JavaScript/TypeScript Architect + Developer Advocate, London UK — It’s time to build your masterpiece – can you design a platform and a framework used by the NHS, HMRC, Valve, and Microsoft?

CareersJS

Frontend Developer at X-Team (Remote) — Join the most energizing community for developers and work on projects for Riot Games, FOX, Sony, Coinbase, and more.

X-Team

Find Your Next Job Through Vettery — Create a profile on Vettery to connect with hiring managers at startups and Fortune 500 companies. It's free for job-seekers.

Vettery

🧑‍💻 Looking to share your job listing in Frontend Focus? There's more info here.

📙 Tutorials, Articles & Opinion

Creating CSS Shapes with Emoji — This is pretty neat. A mash-up of sorts, bringing together CSS Shapes with various 😎 emoji to create interesting text-wrapping effects.

Preethi Sam

Getting Started with Chrome's Origin Trials — Origin trials give you access to a new or experimental features before they are made available to everyone. Here’s how to register for them.

Sam Dutton

Comparing Tools for Quality Engineering for Web UIs — When tasked with automating his front-end tests, a developer set out to explore the options and shares an interesting comparison table here.

Vitali Malinouski

Anima 4.0: Go Straight From Design to React in the Design Handoff — Lets you cherry-pick elements straight from a design and get fully written React components that just work. Here's more about the Anima 4.0 release.

Geoff Graham

Web Performance: 11 Must-Read Tips to Give Your Site a Speed Boost

Shopify Partners sponsor

When Will Web Browsers Be Complete? — A short exploration into the ‘end game’ of web browsers. Lots of chatter on this over on HN too.

Lee LF94

How to Timeout a fetch() Request — How to use setTimeout(), the abort controller, and fetch() API to make requests with a configurable timeout.

Dmitri Pavlutin

How to Build A Progressively Enhanced Accordion Component with Vanilla JS

Chris Ferdinandi

🔧 Code, Tools and Resources

Radix Icons: A Crisp Set of 15×15 Icons in a Variety of Formats — Assets available for Figma, Sketch, IconJar, SVG, installable via npm, and as React components.

modulz

A Better Way to Work With Git? — Trying to remember all those Git commands? Still afraid of using Git’s advanced features? There’s a better way.

Tower sponsor

NSFW JS: TensorFlow-Powered Client Side Indecent Content Checking — Would it be helpful for you to detect.. ‘unseemly’ images on the client side? Enter NSFW JS. We first featured this over a year ago but it’s just had a significant performance-oriented update.

Infinite Red, Inc.

Butter Slider: A Simple Drag and Hold Slider with No Dependencies — You can set it up with data-* attributes in the HTML with a simple init() call, or do it from your script. Demo here.

Armand SALLE

Pure CSS Oil Painting — Another amazing project from Diana, all done with just HTML and CSS. This time the page is presented like a game character creation screen, in which you can customize elements - such as hair color. The detail on the necklace is particularly impressive.

Diana Smith

Rocket Validator: Automated Accessibility Scanner for Large Sites — Not free, but you can sign up for a trial. This tool will automatically scan your site, from a single starting URL, to find markup and accessibility errors and warnings.

rocket validator

Fingerprint JS 3.0: Modern and Flexible Browser Fingerprinting Library — With v3 it’s become completely modular and has been rewritten in TypeScript. Definitely one of those ‘please use this for good, not evil’ type projects though.

FingerprintJS


by via Frontend Focus

Security Researchers Highlight 17 Android Gaming Apps on Google Play Store That Can Bombard Users With Ads

After receiving a report from the Czech antivirus company, Avast, about twenty-one apps that were infected with codes of adware, Google (so far) decided to take down eighteen of those apps that were consistently reported for showing irrelevant ads (while 3 of them are still available in the Play...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Arooj Ahmed via Digital Information World

YouTube App Gets Upgraded With Gesture Controls and Playback Options

YouTube is really trying to emphasize the fact that users would want to use their app on mobile phones and it is trying to make the smartphone YouTube viewing experience much better than might have been the case otherwise by adding lots of new features to try and meet this end. Some of the new...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Zia Muhammad via Digital Information World