Guides
Client Utilities
Remix PWA library of client utilities to spice up your PWA native experience. APIs to add that cherry-on-top feel to your PWA.
A new addition to the Remix PWA collection is @remix-pwa/client
, a library dedicated to enhancing in-browser experience.
The list might seem scanty 😉, but the functionalities supported here are those widely supported by browsers. A lot of the features are still in the works by browsers, but we are excited to share what we have so far. This docs format would be breaking down each API based on a collective API (Clipboard API, for example). Without further ado, let's get started.
One more thing to note, almost every API returns a minimum of a Promise
object. This is to ensure that the API
is asynchronous and doesn't block the main thread and also as a checker (wether things went well or south), the interface
can be defined as follows:
type ClientAPI = Promise<ClientResponse>;
// When things do work
interface ClientResponse {
ok: boolean; // true
message: string;
}
// When things go south (or break)
// i.e an error is thrown
interface ClientError {
ok: boolean; // false
message: string;
}
Note, that in some cases (like readTextFromClipboard
), it returns additional fields with it (in this case, text
is returned with the two fields). And some don't return anything at all.
Clipboard API
copyTextToClipboard
This API allows you to copy text to the clipboard. It's a simple API that takes in a string as its only argument.
import { copyTextToClipboard } from '@remix-pwa/client'
copyTextToClipboard('Hello, world!')
copyImageToClipboard
This API allows you to copy an image to the clipboard. It takes in an image URL as its only argument.
import { copyImageToClipboard } from '@remix-pwa/client'
copyImageToClipboard('https://example.com/image.png')
readTextFromClipboard
This API allows you to read text from the clipboard. It returns a Promise
object with the text as its value.
import { readTextFromClipboard } from '@remix-pwa/client'
readTextFromClipboard().then(({ text }) => {
console.log(text)
});
// or await it if you wish
const { text } = await readTextFromClipboard();
readFilesFromClipboard
This API allows you to read files from the clipboard. It returns a Promise
object with the files as its value.
import { readFilesFromClipboard } from '@remix-pwa/client'
readFilesFromClipboard().then(({ files }) => {
console.log(files)
});
clipboardSupported
This API allows you to check if the clipboard API is supported by the browser. It returns a Promise
object with a boolean as its value.
It is typically a feature of every major section, it's a good thing to have on hand when you need to check if the API is supported 👍.
import { clipboardSupported } from '@remix-pwa/client'
const isSupported = await clipboardSupported();