Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip improvements #41

Open
Terro216 opened this issue Aug 26, 2022 · 3 comments
Open

Tooltip improvements #41

Terro216 opened this issue Aug 26, 2022 · 3 comments

Comments

@Terro216
Copy link
Member

useEffect(() => {
recalculatePosition()
}, [])
useEffect(() => {
recalculatePosition()
}, [props.position])

При монтировании компонента выполняются все эффекты, следовательно, функция recalculatePosition() вызывается дважды
Предлагаю убрать верхний useEffect


setStyles({
"bottom": props.position === "bottom",
"top": props.position === "top",
"right": props.position === "right",
"left": props.position === "left",
"bottom-left": props.position === "bottom-left",
"bottom-right": props.position === "bottom-right",
"top-left": props.position === "top-left",
"top-right": props.position === "top-right",
"left-top": props.position === "left-top",
"left-bottom": props.position === "left-bottom",
"right-top": props.position === "right-top",
"right-bottom": props.position === "right-bottom",
})

Можно упростить?

setStyles({ [props.position]: true })

function setStyles(condition: any) {

Такая идея есть

function setStyles(condition) {
const position = Object.keys(condition)[0]
   const tooltipStyless = {
     top: position==='top'||position==='top-left'||position==='top-right' ? -tooltipHeight - 10 : position==='right'||position==='left' ? centerVertical : -6
     left: ...,
     right: ...,
     bottom: ...,
   }
   classes.add(styles[`tooltip-content-${position}`])
   setTooltipStyles(tooltipStyless)

А как же &&


ref={(e)=>{
tooltipContent.current = e;
}}

Почему нельзя просто ref={tooltipContent}



Может вместо elem назвать tooltipWrapper/tooltipRef (я когда в первый раз в проектах увидел, не сразу понял, что это за elem)

@Terro216
Copy link
Member Author

*В 3 пункте const position = Object.keys(condition).find(key=>condition[key])

@Terro216
Copy link
Member Author

@baikinkirill 🏂🏻

@baikinkirill
Copy link
Member

Ух, как многа всего

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants