Skip to content

Instantly share code, notes, and snippets.

View tuantvk's full-sized avatar
🎉
Happy coding 🎉

tuantvk tuantvk

🎉
Happy coding 🎉
View GitHub Profile
@tuantvk
tuantvk / rn_build_script.sh
Last active July 14, 2021 07:21
Build script on Android for React Native.
#! /usr/bin/env bash
# change env to dev
cat env.dev > .env;
cat documents/google-services/google-services-dev.json > android/app/google-services.json;
cat <<END >android/app/src/main/res/values/strings.xml
<resources>
<string name="app_name">Dev Example</string>
@tuantvk
tuantvk / react-native-mobx-context.js
Last active April 20, 2021 17:06
Example for React Native use Mobx and React Context
// store/pokemon.store.js
import {
get,
computed,
action,
makeAutoObservable,
createTransformer,
} from "mobx";
class PokemonStore {
@tuantvk
tuantvk / react-native-formik.js
Created April 6, 2021 09:37
React Native Formik
import React from 'react';
import {
View,
Text,
TextInput,
Button,
StyleSheet,
} from 'react-native';
import { Formik } from 'formik';
import * as yup from 'yup';
@tuantvk
tuantvk / react-native-react-hook-form.js
Last active May 31, 2024 07:36
React Native use React Hook Form
import React from 'react';
import {
View,
Text,
TextInput,
Button,
StyleSheet,
} from 'react-native';
import { Picker } from '@react-native-picker/picker';
import { useForm, Controller } from 'react-hook-form';
@tuantvk
tuantvk / formatToString.js
Last active August 16, 2021 10:20
Format object values to object string
function formatToString(obj) {
let a = {};
Object.entries(obj).forEach(([key, value]) => {
if (value) {
if ((Array.isArray(value) && value.length > 0)
|| (typeof value === "object" && Object.keys(value).length > 0)
|| (typeof value !== "object" && (String(value).length > 0))
) {
a[key] = parseInt(value) === 0 ? '' : value;
} else {
@tuantvk
tuantvk / cleanTagHtml.js
Created December 17, 2020 02:05
Strip HTML tags from string in JavaScript
function cleanTagHtml(str) {
if (str && str.trim().length) {
let data = [];
let arr = str
.replace(/<\/?[^>]+(>|$)/g, "")
.split("&nbsp;");
// break one line when multiple &nbsp;
for (let i = 0; i < arr.length; i++) {
if (arr[i] && arr[i].trim()) {
Button.Brown = ({ onPress }) => (
<Button
onPress={onPress}
header="Click here"
buttonStyle={styles.brownButton}
/>
);
// StyleSheet
brownButton: {
const Button({
onPress,
label = 'Click me',
buttonStyle,
textColor,
}) => {
return (
<TouchableOpacity style={buttonStyle} onPress={onPress}>
<Text style={textColor}>{label}</Text>