Skip to content

Instantly share code, notes, and snippets.

Daniele Zurico daniele-zurico

Block or report user

Report or block daniele-zurico

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View index.js
import React from 'react'
import {Rule} from '@cesium133/forgjs'
interface Validation {
rule: any
message: string
}
const useValidation = (value: string, validation: Validation) => {
const [validity, setValid] = React.useState({valid: true, message: ''})
View index.js
const {gql} = require('apollo-server');
const typeDefs = gql`
extend type Query {
book(id: ID!): Book
books: [Book]
}
type Book {
id: ID!
title: String
author: Author
View index.js
const {gql} = require('apollo-server');
const typeDefs = gql`
extend type Query {
author(id: ID!): Author
authors: [Author]
}
type Author {
id: ID!
name: String
surname: String
View index.js
const {ApolloServer} = require('apollo-server');
const server = new ApolloServer({
modules: [
require('./modules/author'),
require('./modules/books')
]
})
server
.listen()
.then(({url}) => console.log(`server is running at ${url}`));
View author.js
type Book {
title: String
author: Author
}
type Author {
name: String
books: [Book]
}
View todoRef.tsx
import React, { useState, useReducer, useRef } from "react";
const todoListReducer = (
state: string[],
action: { type: string; value: string }
) => {
switch (action.type) {
case "ADD":
return [...state, action.value];
case "REMOVE":
View TabSwitcher-final.tsx
import React, { createContext, useState, useContext } from "react";
const context = createContext({
activeTabId: "a",
changeTab: (id: string) => {}
});
const Tab = ({ id, children }: any) => {
const tab = useContext(context);
return <div onClick={() => tab.changeTab(id)}>{children}</div>;
View gist:87bf0b4f7c154dd3dad91060fb9b5c1a
import React, { createContext, useState, useContext } from "react";
const context = createContext({
activeTabId: "a",
changeTab: (id: string) => {}
});
const Tab = ({ id, children }: any) => {
const tab = useContext(context);
return <div onClick={() => tab.changeTab(id)}>{children}</div>;
View TabandTabPanel.tsx
const Tab = ({ id, children }: any) => {
const tab = useContext(context);
return <div onClick={() => tab.changeTab(id)}>{children}</div>;
};
const TabPanel = ({ whenActive, children }: any) => {
const tab = useContext(context);
return tab.activeTabId === whenActive ? children : null;
};
View TabSwitcher.tsx
const TabSwitcher = ({ children }: any) => {
const [activeTabId, setActiveTab] = useState<string>("a");
const changeTab = (newTabId: any) => {
setActiveTab(newTabId);
};
return (
<context.Provider
value={{
activeTabId: activeTabId,
You can’t perform that action at this time.