In this guide, you will learn about Mux Uploader and how to use it in your web application.
Mux Uploader has 2 packages:
@mux/mux-uploader
: the web component, compatible with all frontend frameworks@mux/mux-uploader-react
: the React component, for usage in ReactBoth are built with TypeScript and can be installed either via npm
, yarn
or the hosted option on jsdelivr
.
npm install @mux/mux-uploader@latest #or @mux/mux-uploader-react@latest
yarn add @mux/mux-uploader@latest #or @mux/mux-uploader-react@latest
<script src="https://cdn.jsdelivr.net/npm/@mux/mux-uploader"></script>
<!--
or src="https://cdn.jsdelivr.net/npm/@mux/mux-uploader-react"
-->
The only required value to use Mux uploader is endpoint
.
Using in HTML just requires adding the hosted <script>
tag to your page and then adding the <mux-uploader>
element where you need it.
For our React implementation, you can use it just like you would any other React component.
Because Svelte supports web components, it doesn't need a separate wrapper component like React. View the SveltKit example in the Mux Elements repo for a fully functioning example.
<script context="module" lang="ts">
export const prerender = true;
</script>
<script lang="ts">
// this prevents the custom elements from being redefined when the REPL is updated and reloads, which throws an error
// this means that any changes to the custom element won't be picked up without saving and refreshing the REPL
// const oldRegister = customElements.define;
// customElements.define = function(name, constructor, options) {
// if (!customElements.get(name)) {
// oldRegister(name, constructor, options);
// }
// }
// import { page } from '$app/stores';
import { onMount } from "svelte";
onMount(async () => {
await import("@mux/mux-uploader");
});
</script>
<mux-uploader endpoint="https://httpbin.org/put" />
Because Vue supports web components, it doesn't need a separate wrapper component like React. View the Vue example in the Mux Elements repo for a fully functioning example.
<script setup lang="ts">
import "@mux/mux-uploader";
</script>
<template>
<main>
<mux-uploader endpoint="https://httpbin.org/put" />
</main>
</template>