Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ianobermiller's full-sized avatar

Ian Obermiller ianobermiller

View GitHub Profile
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// Create a ref that we add to the element for which we want to detect outside clicks
const ref = useRef();
// State for our modal
const [isModalOpen, setModalOpen] = useState(false);
const openModal = useCallback(() => setModalOpen(true), []);
const closeModal = useCallback(() => setModalOpen(false), []);
import { useState, useEffect, useRef } from 'react';
// Usage
function App() {
// Ref for the element that we want to detect whether on screen
const ref = useRef();
// Call the hook passing in ref and root margin
// In this case it would only be considered onScreen if more ...
// ... than 300px of element is visible.
const onScreen = useOnScreen(ref, '-300px');
@ianobermiller
ianobermiller / radium-issue-462.jsx
Last active January 4, 2016 19:11 — forked from YonasBerhe/gist:ce2fea747650ee7d9d5c
Hoisting issue using radium
import Radium from 'radium';
import React from 'react';
import ReactDOM from 'react-dom';
// import Radium, { Style } from 'radium';
var FakeUser = React.createClass({
getInitialState: function() {
return {firstname: '', lastName: '', gender: '', location: '', email: '', username: '', password: '', picture: ''};