Skip to content

Instantly share code, notes, and snippets.

View yoovanr's full-sized avatar

Artem Misiura yoovanr

  • Porto, Portugal
View GitHub Profile
@yoovanr
yoovanr / actions.games.js
Last active May 1, 2020 17:23
[React] Action and Reducer Examples
import GamesService from '../../services/games'
import store from '../index'
function getGamesAction () {
return async (dispatch) => {
dispatch({ type: 'GET_GAMES_REQUEST'})
try {
const { data } = await GamesService.getGames()
@yoovanr
yoovanr / webview.js
Created May 1, 2020 17:24
[React Native] Custom WebView Component Example
// We use useImperativeHandle for having ability to call methods from parent component.
// We use onMessage method from WebView for triggering needed states from any web apps.
import React, { forwardRef, useImperativeHandle, useRef, memo } from 'react'
import { WebView } from 'react-native-webview'
const WebViewLink = forwardRef(({ onMessage }, ref) => {
const webviewRef = useRef()
@yoovanr
yoovanr / login.js
Last active May 1, 2020 17:29
[React Native] Login Screen Example
// We use react-hook-form library for form validations
// We use react-native-elements library for UI components
import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { StatusBar, View, TextInput, ActivityIndicator } from 'react-native'
import { Button, Text } from 'react-native-elements'
import { useForm } from 'react-hook-form'
@yoovanr
yoovanr / client.js
Created May 1, 2020 17:33
[Vue] Vuex Module Example
import { instance } from '../../api'
const state = {
statsGeneral: [],
loadingStatsGeneral: true,
statsClients: [],
loadingStatsClients: true
}
@yoovanr
yoovanr / instance.js
Created May 1, 2020 17:37
[React] Axios Instance Example
import { Alert } from 'react-native'
import axios from 'axios'
import SocketService from './socket'
import store, { actions } from '../store'
import config from '../config'
// utils/cookies.js
import Cookies from 'cookies'
import cookieCutter from 'cookie-cutter'
// Default server side cookies instance
let serverSideCookiesInstance = null
// Set a new server side cookies instance
const setServerSideCookiesInstance = (ctx) => {
// pages/_app.js
import React from 'react'
import CookiesUtils from '../utils/cookies'
const App = () => {
// ...
}
// pages/index.js
import React, { useEffect } from 'react'
import CookiesUtils from '../utils/cookies'
const HomePage = () => {
useEffect(() => {
CookiesUtils.getItem('server-side-cookies') // Output: Aloha from server side cookies!
@yoovanr
yoovanr / meta-tags.js
Last active July 23, 2021 10:47
[Vue] helpers/meta-tags.js
const generateMetaTags = (params) => {
const metaTags = []
const validMetaTags = ['description']
validMetaTags.forEach((metaTag) => {
if (params[metaTag]) {
metaTags.push({
hid: `${metaTag}`,
name: `${metaTag}`,
content: params[metaTag],
@yoovanr
yoovanr / oauth.js
Created July 23, 2021 10:42
[Vue] store/oauth.js
export const state = () => ({
signinLoading: false,
logoutLoading: false,
})
export const getters = {
signinLoading: (state) => state.signinLoading,
logoutLoading: (state) => state.logoutLoading,
}