Skip to content

Instantly share code, notes, and snippets.

import React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { createSlice } from '@reduxjs/toolkit'
// 1) Create state and actions/reducers
const counterSlice = createSlice({
name: 'counter',
initialState: {
value: 0,
},
reducers: {
// App.js
import { QueryClient, QueryClientProvider} from 'react-query'
const queryClient = new QueryClient()
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Component />
</QueryClientProvider>
)
}
// Auth.js
const AuthContext = createContext({username: '', role: ''});
export function useAuth() {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within a AuthProvider');
}
return context;
}
export function AuthProvider({ children }) {
const initialState = {count: 0};
function reducer(state, action) {
switch (action.type) {
case 'increment':
return {count: state.count + 1};
case 'decrement':
return {count: state.count - 1};
case 'set':
return {count: action.count};
case 'reset':
function Counter({initialCount: 42}) {
const [count, setCount] = useState(initialCount);
return (
<>
Count: {count}
<button onClick={() => setCount(initialCount)}>Reset</button>
<button onClick={() => setCount(prevCount => prevCount - 1)}>-</button>
<button onClick={() => setCount(prevCount => prevCount + 1)}>+</button>
</>
);
// 1)
let isOpen = false;
// 2)
let addressForm = {
first: "Donald",
last: "Duck",
street: "Webfoot Walk",
no: "1313",
town: "Duckburg",
state: "Calisto",
...
"electronInstallerDebian": {
"icon": "./icon.svg",
"categories": [
"Utility"
],
"homepage": "https://foo.com"
},
...
const isDevMode = process.execPath.match(/[\\/]electron[\\/]/);
"description": "Rebuild of the gtk3-demo-application with electron",
...
"linux": [
"deb
]
...
"electronPackagerConfig": {
"packageManager": "yarn",
"executableName": "electron-react-example",
"icon": "./icon.svg"
...
{
label: 'Help', role: 'help',
submenu: [ submenu: [
{ {
label: 'About', label: 'About',
...
if (process.platform === 'darwin') {
const name = app.getName();
menu.unshift({