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
| fetch('/api/recipe').then(res => { | |
| const data = res.json() | |
| //do smthng with react | |
| return data | |
| }) | |
| .then(parsedJSON => { | |
| fetch(`/api/recipes/${data.id}`) | |
| }) |
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
| const STORE = { | |
| score: 0, | |
| currentQuestionIndex: 0, | |
| questions: [ | |
| { | |
| title: 'How many players in a team, y\'all?', | |
| answers: [ | |
| '12', | |
| '11', |
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
| /* const listItemTemp = ('<li>' + | |
| '<span class="shopping-item"></span>' + | |
| '<div class="shopping-item-controls">' + | |
| '<button class="shopping-item-toggle">' + | |
| '<span class="button-label">check</span>' + | |
| '</button>' + | |
| '<button class="shopping-item-delete">' + | |
| '<span class="button-label">delete</span>' + | |
| '</button>' + | |
| '</div>' + |
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 React, { Component } from 'react'; | |
| import slugify from 'slugify'; | |
| import pTypes from 'prop-types'; | |
| // This object will allow us to | |
| // easily convert numbers into US dollar values | |
| // React propTypes | |
| const USCurrencyFormat = new Intl.NumberFormat('en-US', { | |
| style: 'currency', | |
| currency: 'USD' |
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 Async({promiseFn, fallback, errFallback, children}){ | |
| const [state, setState] = useState('initial') | |
| useEffect(()=>{ | |
| promiseFn().then(()=>{ | |
| setState('resolved') | |
| }).catch(()=>{ | |
| setState('error') | |
| }) | |
| }) |
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 React, { useState, useEffect, useContext } from 'react'; | |
| const AppContext = React.createContext(null); | |
| export default AppContext; | |
| export const defaultData = { | |
| loadedItems:[] | |
| } | |
| // Context provider | |
| export const AppContextProvider = ({ initialData, children }) => { |
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 * as yup from 'yup'; | |
| const getPostSchema = (catIDs) => { | |
| const schema = yup.object().shape({ | |
| title: yup.string() | |
| .label('Titlul') | |
| .required().min(10).max(255), | |
| content: yup.string() | |
| .label('Textul') | |
| .required().min(20), | |
| cat_id: yup.number() |
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
| // this wraps an async express route handler function into a try-catch | |
| // it returns a new function which handles failures gracefully | |
| // by sending a JSON encoded message and a HTTP 500 (internal server error) status code | |
| function expressTryCatchWrapper(requestHandler) { | |
| return async function (req, resp, next) { | |
| try { | |
| await requestHandler(req, resp, next) | |
| } catch (ex) { | |
| console.error(`expressTryCatch ERROR ${req.url}`, ex) | |
| if (resp.headersSent) { |
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
| require("dotenv").config(); | |
| const express = require("express"); | |
| const morgan = require("morgan"); | |
| const cors = require("cors"); | |
| const helmet = require("helmet"); | |
| const { NODE_ENV } = require("./config"); | |
| const app = express(); | |
| const morganOption = NODE_ENV === "production" ? " tiny" : "common"; |
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
| export const withLayout = (C, cProps = {}) => { | |
| const name = `withLayout-${C.displayName || C.name}` | |
| function WithLayout(props) { | |
| return ( | |
| <Layout {...props}> | |
| <C {...cProps} /> | |
| </Layout> | |
| ) | |
| } | |
| WithLayout.displayName = name |