preact/hooks#useContext JavaScript Examples
The following examples show how to use
preact/hooks#useContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Counter.jsx From merkur with MIT License | 6 votes |
export default function Counter({ counter }) {
const widget = useContext(WidgetContext);
return (
<div>
<h3>Counter widget:</h3>
<p>Count: {counter}</p>
<button onClick={widget.onClick}>increase counter</button>
<button onClick={widget.onReset}>reset counter</button>
</div>
);
}
Example #2
Source File: index.js From shorts-ui with MIT License | 6 votes |
Button = ({ pocket, image, title, subtitle }) => {
const ashProperties = useContext(PropertiesContext);
const pockets = ashProperties?.cargoPocketsEmptied?.split(',')?.map((s) => parseInt(s.trim(), 10));
const pocketInt = parseInt(pocket, 10);
const pocketEmptied = ashProperties?._cargoPocketEmptied == 'true';
return (
<button
onClick={handlePocket}
data-pocket={pocketInt}
title={`Pocket ${pocketInt}`}
disabled={pocketEmptied || pockets?.includes(pocketInt)}
class={cx(style.btn, pockets?.includes(pocketInt) && style['btn-grey'])}
>
<img src={image} />
<div>
{title}
<br />
{subtitle && subtitle.length > 0 ? <small>{subtitle}</small> : false}
</div>
</button>
);
}
Example #3
Source File: appState.js From v8-deopt-viewer with MIT License | 5 votes |
useAppState = () => useContext(AppStateContext)
Example #4
Source File: appState.js From v8-deopt-viewer with MIT License | 5 votes |
useAppDispatch = () => useContext(AppDispatchContext)
Example #5
Source File: toast.js From rctf with BSD 3-Clause "New" or "Revised" License | 5 votes |
export function useToast () {
const toast = useContext(ToastCtx)
return { toast }
}
Example #6
Source File: lisItem.js From domicilioBoilerplate with GNU Affero General Public License v3.0 | 5 votes |
ListItem = (props) => {
const { name, tel, site, mail, payments, services, note, newEntry } = props;
const action = useContext(Action);
const encodedName = encodeURIComponent(name);
const encodedCity = encodeURIComponent(process.env.PREACT_APP_CITY);
const searchUrl = `https://www.google.com/search?q=${encodedName}%20${encodedCity}`;
const isInfoVisible = Boolean(Array.isArray(tel) || site || mail || payments || services || note);
return (
<article class={`relative rounded-lg border border-gray-500 bg-gray-200 p-4 md:p-5 my-5 text-md lg:text-xl font-semibold text-gray-700 ${newEntry ? "new-entry" : ""}`}>
<div class="flex justify-between items-center">
<span>
<a class="hover:underline" href={searchUrl} target="_blank" rel="noopener noreferrer">{name}</a>
</span>
<div class="flex">
{isInfoVisible &&
<span
onClick={(e) => action.setPopupNumbers(e, props)}
class="inline-block mx-1 md:mx-2 w-8 h-8 cursor-pointer text-center leading-8 bg-blue-300 rounded-lg"
role="img"
aria-label="more info"
>
ℹ️
</span>
}
{mail && !site && !tel && (
<a href={`mailto:${mail}`}>
<span
class="inline-block mx-2 w-8 h-8 bg-orange-300 text-center leading-8 rounded-lg cursor-pointer"
role="img"
aria-label="mail"
>
✉️
</span>
</a>
)}
{site && !tel && (
<a href={`${site}`}>
<span
class="inline-block mx-2 w-8 h-8 bg-orange-300 text-center leading-8 rounded-lg cursor-pointer"
role="img"
aria-label="website"
>
?
</span>
</a>
)}
{tel && (
<a href={`tel:${tel}`} onClick={(e) => Array.isArray(tel) && action.setPopupNumbers(e, props)}>
<span
class="inline-block mx-2 w-8 h-8 bg-green-300 text-center leading-8 rounded-lg cursor-pointer"
role="img"
aria-label="telephone"
>
?
</span>
</a>
)}
</div>
</div>
</article>
);
}