Dev Helpers
← Back

Priority promotion control

Import and render <PriorityPromotionControl /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/PriorityPromotionControl.tsx

import { useState } from "react";

export default function PriorityPromotionControl({
  entries = ["Beta", "Alpha", "Gamma"],
}: { entries?: string[] } = {}) {
  const [top, set] = useState<string | null>(null);
  return (
    <ul>
      {[...entries]
        .sort((a, b) => Number(b === top) - Number(a === top))
        .map((v, i) => (
          <li key={i}>
            {v} <button onClick={() => set(v)}>Pin first</button>
          </li>
        ))}
    </ul>
  );
}