Skip to content

Commit

Permalink
fix(md): minor improvements based on feedback from #9269 (#9289)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranihorev authored Jun 4, 2021
1 parent c72702b commit 75a3a25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { reverse } from 'lodash';
import React from 'react';
import { atom, useRecoilState } from 'recoil';

import { useElementDimensions } from 'core/presentation/hooks/useDimensions.hook';
import { useDimensions } from 'core/presentation/hooks/useDimensions.hook';
import { logger } from 'core/utils';

const STORAGE_KEY = 'MD_environmentsDirection';
Expand All @@ -25,7 +25,7 @@ const environmentsDirectionState = atom<Direction>({
// The goal of this hook is to store the value in an atom to be shared across the app but also update the local storage
const useEnvironmentDirection = () => {
const [direction, setDirection] = useRecoilState(environmentsDirectionState);
React.useLayoutEffect(() => {
React.useEffect(() => {
localStorage.setItem(STORAGE_KEY, direction);
}, [direction]);

Expand Down Expand Up @@ -56,7 +56,7 @@ interface IEnvironmentsRenderProps {
export const EnvironmentsRender = ({ className, children }: IEnvironmentsRenderProps) => {
const { direction } = useEnvironmentDirection();
const ref = React.useRef(null);
const { width } = useElementDimensions({ ref, isActive: direction === 'sideBySide' });
const { width } = useDimensions(ref, { isActive: direction === 'sideBySide' });
let numEnvironments = 1;
if (Array.isArray(children)) {
numEnvironments = children.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import React from 'react';
const getElementDimensions = (ref: React.RefObject<HTMLElement>) =>
ref.current ? { width: ref.current.offsetWidth, height: ref.current.offsetHeight } : { width: 0, height: 0 };

export const useElementDimensions = ({
ref,
delay = 200,
isActive = true,
}: {
ref: React.RefObject<HTMLElement>;
delay?: number;
isActive?: boolean;
}) => {
export const useDimensions = (
ref: React.RefObject<HTMLElement>,
{
delay = 200,
isActive = true,
}: {
delay?: number;
isActive?: boolean;
},
) => {
const [dimension, setDimension] = React.useState(getElementDimensions(ref));

React.useLayoutEffect(() => {
Expand Down

0 comments on commit 75a3a25

Please sign in to comment.