This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
final int id; | |
final String name; | |
const User({ | |
required this.id, | |
required this.name, | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Animal { | |
Cat, | |
Dog, | |
} | |
hello(Animal animal) { | |
return switch (animal) { | |
Animal.Cat => 'is Cat', | |
Animal.Dog => 'is Dog', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:hooks_riverpod/hooks_riverpod.dart'; | |
extension AutoDisposeRefCache on AutoDisposeRef { | |
static final Map<String, Timer> _timersMap = {}; | |
// Keeps the provider alive for [duration] since when it was first created | |
void cacheFor(Duration duration, {String? cacheKey}) { | |
if (cacheKey != null && _timersMap.containsKey(cacheKey)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:hooks_riverpod/hooks_riverpod.dart'; | |
extension AutoDisposeRefCache on AutoDisposeRef { | |
static final Map<String, Timer> _timersMap = {}; | |
// Keeps the provider alive for [duration] since when it was first created | |
void cacheFor(Duration duration, {String? cacheKey}) { | |
if (cacheKey != null && _timersMap.containsKey(cacheKey)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isSSR = () => typeof window === 'undefined'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UserScheme = z.object({ | |
name: z.string().nonempty().max(50), | |
age: z.number().min(1).max(200), | |
}); | |
type Values = z.infer<typeof UserScheme>; | |
type Forms = { | |
setName: (value: string) => void; | |
setAge: (value: number) => void; | |
valid: boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select id, | |
start_at, | |
# date_add(start_at, interval -DAY(start_at) + 1 DAY), | |
end_at | |
from sample_data; | |
# [ | |
# { | |
# "id": 1, | |
# "start_at": "2022-04-01 20:57:07", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
/** | |
* ブラウザバックしたときに処理を実行したいときに使用するhooks | |
*/ | |
export const useOnBrowserBack = (onBrowserBack: () => void) => { | |
useEffect(() => { | |
window.history.pushState(null, '', window.location.pathname); | |
window.addEventListener('popstate', onBrowserBack); | |
return () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
/** | |
* 一度入力した後にリロードすると、確認ダイアログを出す。 | |
*/ | |
export const useOnReloadAlert = () => { | |
useEffect(() => { | |
window.history.pushState(null, '', window.location.pathname); | |
const onReload = (event: BeforeUnloadEvent) => { | |
event.preventDefault(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function chunk(arr, size) { | |
return arr.reduce( | |
(newarr, _, i) => (i % size ? newarr : [...newarr, arr.slice(i, i + size)]), | |
[] | |
) | |
} |
NewerOlder