react-archer icon indicating copy to clipboard operation
react-archer copied to clipboard

arrows don't re-render correctly

Open mohdmujahithali opened this issue 1 year ago • 4 comments

After initial rending the arrow lines appear correctly as shown below

Screenshot 2023-03-07 003923

After opened the accordion of some portion, arrow lines get collapsed and shown as like below,

Screenshot 2023-03-07 003939

Also, while scrolling, arrow lines get collapsed and shown as like below,

Screenshot 2023-03-07 003952

I saw that there is an instance method "refreshScreen" need to be call, when the onscroll event happening. But there is clear documentation regarding that method how to call it? So, could you please provide the working example for "refreshScreen" instance method

Another example

after initial rendering,

Screenshot 2023-03-07 020814

after opened the accordion,

Screenshot 2023-03-07 020828

let me know the working example that how to use instance method "refreshScreen" here.

mohdmujahithali avatar Mar 06 '23 19:03 mohdmujahithali

Hi!

Thank you for the detailed issue.

Can you try calling refreshScreen when your screen moves? For example, if you collapse/uncollapse an accordion, then call refreshScreen afterwards.

const archerRef = useRef()

useEffect(() => {
  archerRef.refreshScreen()
}, [isOpen])

return <ArcherContainer ref={archerRef}>...</ArcherContainer>

pierpo avatar Mar 07 '23 01:03 pierpo

@pierpo

I declared reference as below,

const archerRef = useRef();

Then I got the below error

image

So, I declared reference with null as below,

const archerRef = useRef(null);

Then I got the error for "refreshScreen" function call

image

Does we need to import anything for "refreshScreen" method?

image image image

mohdmujahithali avatar Mar 07 '23 18:03 mohdmujahithali

This is only a type error, I think it would work at runtime.

To solve your error:

// (note: this import does not look good indeed, it needs a fix on the lib's side)
import { ArcherContainerHandle } from 'react-archer/lib/ArcherContainer/ArcherContainer.types';

// ...
const archerRef = useRef<ArcherContainerHandle>(null);

The method does exist, it's only your typing that is wrong 😉

pierpo avatar Mar 07 '23 23:03 pierpo

In case one is searching, the example above is in general correct but your state var might changes earlier in the process causing undefined variable issues.

const archerRef = useRef<ArcherContainerHandle>(null);
  import { ArcherContainerHandle } from 'react-archer/lib/ArcherContainer/ArcherContainer.types';

    useEffect(() => {
        if (archerRef?.current) {
            archerRef.current.refreshScreen()
        }
    }, [zoomLevel]);

Checking for the availability of the ref might help.

lucfranken avatar Nov 17 '23 07:11 lucfranken