Skip to content

Instantly share code, notes, and snippets.

View CryceTruly's full-sized avatar
🎯
Focusing

cryce truly CryceTruly

🎯
Focusing
View GitHub Profile
Here is how you can do it when the items in the arrays are objects.
The idea is to find the array of only the keys in an inner array using the map function
Then foreach of those check if they contain a spectific element key in the outer array.
const existsInBothArrays = array1.filter((element1) =>
array2.map((element2) => element2._searchKey).includes(element1._searchKey),
);
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
import envs from '../config/env';
import {LOGOUT} from '../constants/routeNames';
import * as RootNavigation from '../navigations/RootNavigation';
let headers = {};
const axiosInstance = axios.create({
baseURL: envs.BACKEND_URL,
@CryceTruly
CryceTruly / useRef.js
Created December 16, 2020 05:08
Implementing componentDidUpdate using hooks.
const initialItemsRef = useRef([]);
useEffect(() => {
if (userItems.length) {
const prev = initialItemsRef.current;
initialWalletsRef.current = <whatToCheckForChanges>;
const newones = initialItemsRef.current;
if (newones.length - prev.length === 1) {
const difference = newones.find((x) => !prev.map((i) => i.AccountNumber).includes(x.AccountNumber));
import "./App.css";
import { useState } from "react";
function App() {
const options = [
{
header: {
name: "Account",
},
@CryceTruly
CryceTruly / autoheight.js
Created November 1, 2020 19:22
react input component with dynamic height
import React, { useState } from "react";
import "./style.css";
const DynamicHeightInput = () => {
const [textareaHeight, setTextareaHeight] = useState(42);
const [formValue, setFormValue] = useState({});
const onChange = (event) => {
event.preventDefault();
event.persist();
import React, { useState } from "react";
import "./App.css";
function App() {
const [form, setForm] = useState([]);
const prevIsValid = () => {
if (form.length === 0) {
return true;
}
from django.http import JsonResponse
def error_404(request, exception):
message = ("The endpoint you are trying to access might "
"have been removed, "
"had its name changed, or is temporarily unavailable. "
"Please check the documentation here : "
"/ docs and try again later.")
response = JsonResponse(data={"message": message, 'status_code': 404})
from rest_framework.views import exception_handler
from rest_framework import status
from django.http import Http404
def custom_exception_handler(exc, context):
"""
This function will handle errors that are returned by
the different views.
The `handlers` dictionary will map
import React, { useState } from "react";
import "./App.css";
function App() {
const [form, setForm] = useState([]);
const [submitted, setFormSubmitted] = useState(false);
const someEmpty = form.some(
(item) => item.Platform === "" || item.Username === ""
);
export default [
{
text: "Afghanistan (+93)",
value: "+93",
flag: "af",
key: "af",
},
{
text: "Aland Islands",
value: "",