Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import { act, renderHook } from '@testing-library/react-hooks'; // Don't forget to install this package
import { useValue } from "./useValue";
it("Custom hook hooks:)", () => {
const { result } = renderHook(useValue);
act(() => {
result.current.assignValue('Hello World');
});
expect(result.current.value).toBe('Hello World');
// LoginPage.js
import React from 'react';
import { LoginForm } from 'LoginForm';
import { useValue } from 'useValue';
export default function LoginPage() {
const { value, assignValue } = useValue(false); // Calling our custom hook; false is the initial value this time around
import React from 'react';
import { LoginForm } from 'LoginForm';
import { useValue } from 'useValue';
export default function LoginPage() {
const { value, assignValue } = useValue(false); // Calling our custom hook; false is the initial value this time around
function handleSubmit() {
assignValue(true);
// LoginForm.js
import React from 'react';
import { useValue } from './useValue';
export function LoginForm({ handleSubmit }) {
const { value, assignValue } = useValue(''); // empty string is the initial value;
function handleChange(e) {
@mikekoro
mikekoro / useValue.js
Last active May 9, 2020 05:46
Re-useable Custom Hook
// useValue.js
import React, { useState } from 'react';
export const useValue = (initial_value) => {
const [value, setValue] = useState(initial_value);
const assignValue = (input) => {
setValue(input);
}
// Configure Passport.js
// JWT Stuff
const LocalStrategy = require('passport-local').Strategy;
const passportJWT = require("passport-jwt");
const JWTStrategy = passportJWT.Strategy;
const ExtractJWT = passportJWT.ExtractJwt;
// Use Passport.js & JWTStrategy
<button ng-click="accept()" class="button-accept" ng-if="type == 'inbound'">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="14.356px" height="14.356px" viewBox="0 0 348.077 348.077" style="enable-background:new 0 0 348.077 348.077;" xml:space="preserve"><g><g><g><path d="M340.273,275.083l-53.755-53.761c-10.707-10.664-28.438-10.34-39.518,0.744l-27.082,27.076c-1.711-0.943-3.482-1.928-5.344-2.973c-17.102-9.476-40.509-22.464-65.14-47.113c-24.704-24.701-37.704-48.144-47.209-65.257c-1.003-1.813-1.964-3.561-2.913-5.221l18.176-18.149l8.936-8.947c11.097-11.1,11.403-28.826,0.721-39.521L73.39,8.194C62.708-2.486,44.969-2.162,33.872,8.938l-15.15,15.237l0.414,0.411c-5.08,6.482-9.325,13.958-12.484,22.02C3.74,54.28,1.927,61.603,1.098,68.941C-6,127.785,20.89,181.564,93.866,254.541c100.875,100.868,182.167,93.248,185.674,92.876c7.638-0.913,14.958-2.738,22.397-5.627c7.992-3.122,15.463-7.361,21.941-12.43l0.331,0.294l15.348-15.029C350.631,303.52
.controller('chatCtrl', function($scope, $state) {
// User clicks "Send"
$scope.sendMessage = function(message,recipient) {
if(!message) {
return false
}
angular
.module('app')
.service('xmpp', function($rootScope, $state) {
return {
auth: function(jid, sid, rid) {
// I am using attach instead of connect so you don't need any jid, sid or rid
@media (min-width: 1200px) {
.container {
max-width: 970px;
}
}