Skip to content

Instantly share code, notes, and snippets.

View p32929's full-sized avatar

Fayaz Bin Salam p32929

View GitHub Profile
import 'dart:convert';
dynamic parseJson(String jsonString, String path) {
var json = jsonDecode(jsonString);
List<String> parts = path.split('.');
dynamic element = json;
for (var part in parts) {
if (part.contains('[') && part.contains(']')) {
@p32929
p32929 / VisibilityObserver.tsx
Created May 23, 2024 10:29
a component kinda thingie to detect if an element is visible or hidden by css and came to view etc
import React, { useState, useEffect, useRef } from 'react';
interface VisibilityObserverProps {
children: (props: { elementRef: React.RefObject<HTMLDivElement>, isVisible: boolean }) => JSX.Element;
}
const VisibilityObserver: React.FC<VisibilityObserverProps> = ({ children }) => {
const [isVisible, setIsVisible] = useState(false);
const elementRef = useRef<HTMLDivElement>(null);
@p32929
p32929 / NoSsr.tsx
Created May 23, 2024 10:31
disable SSR on a component
import dynamic from 'next/dynamic'
import React from 'react'
const NoSsr = props => (
<React.Fragment>{props.children}</React.Fragment>
)
export default dynamic(() => Promise.resolve(NoSsr), {
ssr: false
})