Wednesday, July 31, 2019

Fetching Data in React using React Async

You’re probably used to fetching data in React using axios or fetch. The usual method of handling data fetching is to:

  • Make the API call.
  • Update state using the response if all goes as planned.
  • Or, in cases where errors are encountered, an error message is displayed to the user.

There will always be delays when handling requests over the network. That’s just part of the deal when it comes to making a request and waiting for a response. That’s why we often make use of a loading spinner to show the user that the expected response is loading.

See the Pen
ojRMaN
by Geoff Graham (@geoffgraham)
on CodePen.

All these can be done using a library called React Async.

React Async is a promised-based library that makes it possible for you to fetch data in your React application. Let’s look at various examples using components, hooks and helpers to see how we can implement loading states when making requests.

For this tutorial, we will be making use of Create React App. You can create a project by running:

npx create-react-app react-async-demo

When that is done, run the command to install React Async in your project, using yarn or npm:

## yarn
yarn add react-async

## npm
npm install react-async --save

Example 1: Loaders in components

The library allows us to make use of <Async> directly in our JSX. As such, the component example will look like this;

// Let's import React, our styles and React Async
import React from 'react';
import './App.css';
import Async from 'react-async';

// We'll request user data from this API
const loadUsers = () =>
  fetch("https://jsonplaceholder.typicode.com/users")
    .then(res => (res.ok ? res : Promise.reject(res)))
    .then(res => res.json())

// Our component
function App() {
  return (
    <div className="container">
      <Async promiseFn={loadUsers}>
        {({ data, err, isLoading }) => {
          if (isLoading) return "Loading..."
          if (err) return `Something went wrong: ${err.message}`

          if (data)
            return (
              <div>
                <div>
                  <h2>React Async - Random Users</h2>
                </div>
                {data.map(user=> (
                  <div key={user.username} className="row">
                    <div className="col-md-12">
                      <p>{user.name}</p>
                      <p>{user.email}</p>
                    </div>
                  </div>
                ))}
              </div>
            )
        }}
      </Async>
    </div>
  );
}

export default App;

First, we created a function called loadUsers. This will make the API call using the fetch API. And, when it does, it returns a promise which gets resolved. After that, the needed props are made available to the component.

The props are:

  • isLoading: This handles cases where the response has not be received from the server yet.
  • err: For cases when an error is encountered. You can also rename this to error.
  • data: This is the expected data obtained from the server.

As you can see from the example, we return something to be displayed to the user dependent on the prop.

Example 2: Loaders in hooks

If you are a fan of hooks (as you should), there is a hook option available when working with React Async. Here’s how that looks:

// Let's import React, our styles and React Async
import React from 'react';
import './App.css';
import { useAsync } from 'react-async';

// Then we'll fetch user data from this API
const loadUsers = async () =>
  await fetch("https://jsonplaceholder.typicode.com/users")
    .then(res => (res.ok ? res : Promise.reject(res)))
    .then(res => res.json())

// Our component
function App() {
  const { data, error, isLoading } = useAsync({ promiseFn: loadUsers })
  if (isLoading) return "Loading..."
  if (error) return `Something went wrong: ${error.message}`
  if (data)
  
  // The rendered component
  return (
    <div className="container">
      <div>
        <h2>React Async - Random Users</h2>
      </div>
      {data.map(user=> (
        <div key={user.username} className="row">
          <div className="col-md-12">
            <p>{user.name}</p>
            <p>{user.email}</p>
          </div>
        </div>
      ))}
    </div>
  );
}

export default App;

This looks similar to the component example, but in this scenario, we’re making use of useAsync and not the Async component. The response returns a promise which gets resolved, and we also have access to similar props like we did in the last example, with which we can then return to the rendered UI.

Example 3: Loaders in helpers

Helper components come in handy in making our code clear and readable. These helpers can be used when working with an useAsync hook or with an Async component, both of which we just looked at. Here is an example of using the helpers with the Async component.

// Let's import React, our styles and React Async
import React from 'react';
import './App.css';
import Async from 'react-async';

// This is the API we'll use to request user data
const loadUsers = () =>
  fetch("https://jsonplaceholder.typicode.com/users")
    .then(res => (res.ok ? res : Promise.reject(res)))
    .then(res => res.json())

// Our App component
function App() {
  return (
    <div className="container">
      <Async promiseFn={loadUsers}>
          <Async.Loading>Loading...</Async.Loading>
          <Async.Fulfilled>
            {data => {
              return (
                <div>
                  <div>
                    <h2>React Async - Random Users</h2>
                  </div>
                  {data.map(user=> (
                    <div key={user.username} className="row">
                      <div className="col-md-12">
                        <p>{user.name}</p>
                        <p>{user.email}</p>
                      </div>
                    </div>
                  ))}
                </div>
              )
            }}
          </Async.Fulfilled>
          <Async.Rejected>
            {error => `Something went wrong: ${error.message}`}
          </Async.Rejected>
      </Async>
    </div>
  );
}

export default App;

This looks similar to when we were making use of props. With that done, you could break the different section of the app into tiny components.

Conclusion

If you have been growing weary of going the route I mentioned in the opening section of this tutorial, you can start making of React Async in that project you are working on. The source code used in this tutorial can be found in their different branches on GitHub.

The post Fetching Data in React using React Async appeared first on CSS-Tricks.

from CSS-Tricks https://css-tricks.com/fetching-data-in-react-using-react-async/

Fetching Data in React using React Async is available on www.instant-web-site-tools



source https://www.instant-web-site-tools.com/2019/07/31/fetching-data-in-react-using-react-async/

Bringing CSS Grid to WordPress Layouts

A More Accessible Portals Demo

Are Design Pitches Worthwhile?

For most designers – freelance or in-house – generating new business can be a dreaded part of the job. But it necessary to maintain and sustain growth and find new clients. When it comes to finding design work, is there a best way to find jobs? Do you pitch for new business or rely on other methods to find work?

Reasons to Pitch for New Business

There are so many places that freelance designers can pitch for new business, including job boards, and content or design networks, or marketplaces. Some designers may pitch on social media as well.

But is it worth your time to post in these places to generate business?

For some designers, the answer is, “Yes.”

Pitching requires you to think about the type of work and clients you want to take on. This can be a valuable exercise that helps you grow your business strategically and with the type of work you want to do. If you plan to pitch, create specific pitches that respond directly to postings, avoiding generic “I can do any type of design” pitches.

For freelancers with limited time, this can be an ideal situation

Pitching works for designers that want to know exactly where they stand with projects and don’t want to deal with the management of them. Most pitches you submit in response to a job board or marketplace post will detail a specific design need, timeline, and payment for that work. You know everything up front and don’t have to negotiate terms or deal with scope creep. For freelancers with limited time, this can be an ideal situation.

Pitching can help you find an “in” with new clients and turn into long-term work. There are plenty of designers that have found good projects through Behance, Dribbble, and Upwork.

Pitching might be the only way for a new designer to build a strong portfolio. Depending on the stage of your career, this type of work can help generate clients, relationships, and projects that can lead to more work later.

Whether responding to ads and sending pitches is the right choices depends on you and the stage you are at in your career. It’s not for everyone, but for some designers, pitching can be totally worthwhile, and work better than cold calling or trying to generate new business in other ways.

Reasons Not to Pitch

Some designers hate pitching and find that the time spent looking for new business doesn’t generate enough income to support itself. That’s the top reason not to pitch. If you aren’t bringing in work with pitches, it could actually be costing you money. Analyze pitches sent, responses received, and clients you are actually working with. How much time do you spend on pitching versus revenue generated from actual work from pitching?

If the math doesn’t work out to a sustainable hourly rate, pitching might not be the best option for you. It can be a lot of work, without a large return.

Are you charging less or doing work that you’d never put in your portfolio?

When it comes to responding and pitching for projects, there’s almost always a “middle” company or organization that gets a cut of the payment for the job. If you can generate new business own your own, why pay that fee?

Sometimes pitching can feel spammy or doesn’t help you build more business. Are you cutting your worth to respond to a pitch? Are you charging less or doing work that you’d never put in your portfolio? If the answer to either question is yes, then pitching is probably not for you.

Other Ways to Generate New Design Business

Building a reputation as a designer and taking new clients from word-of-mouth recommendations and referrals is the top way most designers seem to want to generate new business.

But you have to have a fairly established client base and good network for this model to be sustainable. For a lot of designers, this often means that seeking outside work starts with responding to pitch requests while building more of a network and portfolio and then moving to other (more profitable) methods of generating new business.

So how do you generate design business?

There’s a funnel for getting design work for freelancers. At the big end of the funnel is work that’s mostly unsolicited and projects are often granted via pitch (such as marketplaces or job boards). These jobs don’t typically include long-term contracts or big fees. At the small end of the funnel is referrals and repeat client work. These jobs come from relationship building, often pay more and result in longer-term business for more experienced designers.

And then there’s everything in the middle:

  • Cold pitches: Soliciting work from clients via cold call, email, or with a pitch letter;
  • Events: Using speaking engagements or conferences to network and make connections that result in design work;
  • Advertising: Using paid advertising, a website, or email/mail to connect with potential clients that might need design services;
  • Social media: Generating business through social media channels by showcasing work or expertise or offering services;
  • Networking and feeders: Connecting with businesses or design agencies that can subcontract overflow work to you.

The reality is that almost every type of connection requires some type of pitch. The colder the pitch (or less connected you are to the potential client) the more work it will probably take to land the job.

Conclusion

So, we are back to the question at hand: Are pitches worthwhile?

Depending on your career stage, the answer is yes. For early career, or new freelance designers, pitching through marketplaces or job boards can help you grow a business on your own or provide just a little extra income from a side hustle.

For designers that are more established and already have a strong network, cold pitching isn’t the go-to option. In the end, most of us have responded to pitches at some point and either loved the simplicity of pitch and respond work or hated the lower income ratio often associated with these jobs.

Personally, pitching was a great way to establish my position in the field. And with years of experience to show now, work comes via referral. So yes, pitches can be worthwhile. They were a building block in my career and I expect many others share a similar experience.

 

Featured image via DepositPhotos.

Source

from Webdesigner Depot https://www.webdesignerdepot.com/2019/07/are-design-pitches-worthwhile/

Are Design Pitches Worthwhile? is republished from https://www.instant-web-site-tools



source https://www.instant-web-site-tools.com/2019/07/31/are-design-pitches-worthwhile/

Tuesday, July 30, 2019

How to Change Slide Size in PowerPoint

While most users are accustomed to the standard 16:9 aspect ratio of presentations, you can change the size of slides in PowerPoint.

You might change to accommodate a different screen size – maybe the older 4:3 aspect ratio – or to create a custom file type. The tool even includes a few predefined sizes to make it easy for you.

You’ll ideally want the size of your presentation to match whatever device it will be shown on (which is why it’s worth asking about the resolution of the screen or projector you’ll be using in advance!)

Here’s how to change slide size in PowerPoint in a few quick steps.

Change Slide Size Between Standard and Widescreen

The two most common sizes for PowerPoint presentations are standard (4:3) and widescreen (16:9) sizes. The standard size has shifted to 16:9 as more computer and projection screens have moved to this size.

Both are presets that exist within the tool.

how to change slide size powerpoint

Open your presentation, click Design in the top menu. Find the Slide Size button and click to see the two sizes. Click the one you want to use.

how to change slide size powerpoint

PowerPoint will give you the option to scale content to the new size.

how to change slide size powerpoint

Note that when you change slide size, it affects all of the slides in the open file. If you scale, that also impacts every slide. Make sure to go through and make sure the design of each still looks as intended before giving the presentation. Some adjustments may be necessary.

Change to Another Standard Size

You can also change the size of PowerPoint slides to match other common sizes, such as A4, banner, or ledger using page setup features.

how to change slide size powerpoint

Open the presentation, click Design in the top menu. Find the Slide Size button and click Page Setup. The current configuration is noted with a check mark.

how to change slide size powerpoint

Pick the size and orientation you want to use from the menu and click OK. You will be prompted to choose whether you want to scale the content up or down here as well.

how to change slide size powerpoint

Change to a Custom Slide Size

You can also use a custom slide size in PowerPoint, making each slide any size you want.

how to change slide size powerpoint

Open the presentation, click Design in the top menu. Find the Slide Size button and click Page Setup. The current configuration is noted with a check mark.

how to change slide size powerpoint

Click custom. Type the desired width and height in the boxes and click OK. You will be asked if you want to scale the content.

how to change slide size powerpoint

Conclusion

When it comes to custom sized slides in PowerPoint, note that not all templates will act the same way when changing size or scaling up or down. Fonts, design elements, and images can sometimes get out of alignment or not quite look the way you want.

While the scale feature is quite helpful, it is important to always go back and check each slide if you change the size after content has already been added to the presentation.

Don’t forget to take a look at our full PowerPoint templates guide, or our collection of the best PowerPoint templates for your next project!

from Design Shack https://designshack.net/articles/software/how-to-change-slide-size-in-powerpoint/

The following post How to Change Slide Size in PowerPoint is republished from Instant Web Site Tools



source https://www.instant-web-site-tools.com/2019/07/31/how-to-change-slide-size-in-powerpoint/

How much specificity do @rules have, like @keyframes and @media?

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

To prove that, we can use the same selector inside and outside of an at-rule and see if it seems to affect specificity.

body {
  background: red;
}
@media (min-width: 1px) {
  body {
    background: black;
  }
}

The background is black. But... is that because the media query increases the specificity? Let's switch them around.

@media (min-width: 1px) {
  body {
    background: black;
  }
}
body {
  background: red;
}

The background is red, so nope. The red background wins here just because it is later in the stylesheet. The media query does not affect specificity.

If it feels like selectors are increasing specificity and overriding other styles with the same selector, it's likely just because it comes later in the stylesheet.

Still, the @keyframes in the original question got me thinking. Keyframes, of course, can influence styles. Not specificity, but it can feel like specificity if the styles end up overridden.

See this tiny example:

@keyframes winner {
  100% { background: green; }
}
body {
  background: red !important;
  animation: winner forwards;
}

You'd think the background would be red, especially with the !important rule there. (By the way, !important doesn't affect specificity; it's a per-rule thing.) It is red in Firefox, but it's green in Chrome. So that's a funky thing to watch out for. (It's been a bug since at least 2014 according to Estelle Weyl.)

The post How much specificity do @rules have, like @keyframes and @media? appeared first on CSS-Tricks.

from CSS-Tricks https://css-tricks.com/how-much-specificity-do-rules-have-like-keyframes-and-media/

The post How much specificity do @rules have, like @keyframes and @media? is republished from The Instant Web Site Tools Blog



source https://www.instant-web-site-tools.com/2019/07/31/how-much-specificity-do-rules-have-like-keyframes-and-media/

Intrinsically Responsive CSS Grid with minmax() and min()

The most famous line of code to have come out of CSS grid so far is:

grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));

Without any media queries, that will set up a grid container that has a flexible number of columns. The columns will stretch a little, until there is enough room for another one, and then a new column is added, and in reverse.

The only weakness here is that first value in minmax() (the 10rem value above). If the container is narrower than whatever that minimum is, elements in that single column will overflow. Evan Minto shows us the solution with min():

grid-template-columns: repeat(auto-fill, minmax(min(10rem, 100%), 1fr));

The browser support isn't widespread yet, but Evan demonstrates some progressive enhancement techniques to take advantage of now.

Direct Link to ArticlePermalink

The post Intrinsically Responsive CSS Grid with minmax() and min() appeared first on CSS-Tricks.

from CSS-Tricks http://evanminto.com/blog/intrinsically-responsive-css-grid-minmax-min/

The blog post Intrinsically Responsive CSS Grid with minmax() and min() Find more on: https://www.instant-web-site-tools/



source https://www.instant-web-site-tools.com/2019/07/31/intrinsically-responsive-css-grid-with-minmax-and-min/

40+ Best Minimal Logo Design Templates

Minimalist logo design is an art. How can you convey your brand with a professional logo, but keep the simplicity of a minimal, clean, and s...