This file contains hidden or 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 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
const MyApp({super.key}); | |
@override |
This file contains hidden or 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:ui' as ui; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
import 'package:flutter/scheduler.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} |
This file contains hidden or 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 useAPI({ url, body }) { | |
const [response, setResponse] = useState(null); | |
const cachedBody = useDeepMemo(() => body, [body]); | |
useEffect(() => { | |
// do the request here | |
}, [url, cachedBody]); | |
return response; | |
} |
This file contains hidden or 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
// you can also use other deep compare functions | |
// e.g. lodash's _.isEqual | |
import { equal } from '@wry/equality'; | |
function useDeepMemo(memoFn, key) { | |
const ref = useRef(); | |
if (!ref.current || !equal(key, ref.current.key)) { | |
ref.current = { key, value: memoFn() }; | |
} | |
This file contains hidden or 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
// usage | |
const response = useAPI({ | |
url: '/api/get-user', | |
body: { userId }, | |
}); | |
// implementation | |
function useAPI({ url, body }) { | |
const [response, setResponse] = useState(null); |
This file contains hidden or 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
useEffect(() => { | |
let ignore = false; | |
const fetchUserData = async () => { | |
const response = await API.getUserData(userId); | |
if (!ignore) { | |
setUserData(response.userData); | |
} | |
}; | |
fetchUserData(); | |
return () => { |
This file contains hidden or 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
useEffect(() => { | |
const fetchUserData = async () => { | |
const response = await API.getUserData(userId); | |
setUserData(response.userData); | |
}; | |
fetchUserData(); | |
}, [userId); |
This file contains hidden or 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
// fix slider not resizing problem | |
function royalslider_fix_tabs() { | |
?> | |
jQuery('[data-uk-tab]').on('show.uk.switcher', function(event, area){ | |
var slider = jQuery('.royalSlider'); | |
if(slider.length) { | |
slider.royalSlider('updateSliderSize', true); | |
} | |
}); |
This file contains hidden or 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
// Replace this part in get_items() function | |
if ( is_array( $request['filter'] ) ) { | |
if (isset($request['filter']['lang'])) { // if get filter[lang] | |
global $sitepress; | |
$sitepress->switch_lang($request['filter']['lang']); // switch language | |
} | |
$args = array_merge( $args, $request['filter'] ); | |
unset( $args['filter'] ); | |
} |
This file contains hidden or 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
<?php | |
// add custom fields to WP REST API | |
function wp_api_encode_acf($data,$post,$context){ | |
$customMeta = (array) get_fields($post['ID']); | |
$data['meta'] = array_merge($data['meta'], $customMeta ); | |
return $data; | |
} |
NewerOlder