Skip to content

Commit

Permalink
fix: Use useRef rather than useState for DOM references
Browse files Browse the repository at this point in the history
  • Loading branch information
bpas247 committed Jul 3, 2019
1 parent 20eb49d commit 1877431
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion www/src/components/ReactPlayground.js
Expand Up @@ -3,7 +3,7 @@
import classNames from 'classnames';
import styled, { css } from 'astroturf';
import qsa from 'dom-helpers/query/querySelectorAll';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import * as ReactBootstrap from 'react-bootstrap';
Expand All @@ -22,6 +22,7 @@ import Sonnet from './Sonnet';

const scope = {
useEffect,
useRef,
useState,
...ReactBootstrap,
ReactDOM,
Expand Down
8 changes: 3 additions & 5 deletions www/src/examples/Overlays/Overlay.js
@@ -1,15 +1,13 @@
function Example() {
const [show, setShow] = useState(false);
const [target, setTarget] = useState(null);

const attachRef = targ => setTarget(targ);
const target = useRef(null);

return (
<>
<Button variant="danger" ref={attachRef} onClick={() => setShow(!show)}>
<Button variant="danger" ref={target} onClick={() => setShow(!show)}>
Click me to see
</Button>
<Overlay target={target} show={show} placement="right">
<Overlay target={target.current} show={show} placement="right">
{({
placement,
scheduleUpdate,
Expand Down
8 changes: 3 additions & 5 deletions www/src/examples/Overlays/TooltipOverlay.js
@@ -1,15 +1,13 @@
function Example() {
const [show, setShow] = useState(false);
const [target, setTarget] = useState(null);

const attachRef = targ => setTarget(targ);
const target = useRef(null);

return (
<>
<Button ref={attachRef} onClick={() => setShow(!show)}>
<Button ref={target} onClick={() => setShow(!show)}>
Click me!
</Button>
<Overlay target={target} show={show} placement="right">
<Overlay target={target.current} show={show} placement="right">
{props => (
<Tooltip id="overlay-example" {...props}>
My Tooltip
Expand Down

0 comments on commit 1877431

Please sign in to comment.