wadackel / react-stack-grid

Pinterest like layout components for React.js
https://wadackel.github.io/react-stack-grid/
MIT License
870 stars 77 forks source link

call updateLayout() function in a fonctional component #68

Closed swisspix closed 4 years ago

swisspix commented 5 years ago

Hi !

I'm kind of new in react an discovered this awesome library but I really want to call the updateLayout function in a fonctional component !

How am I supposed to get the ref from the grid ?

I know it's like that in a class component gridRef={grid => this.grid = grid}

But how do I reference it in a fonctionnal component ?

Many thanks in advance :)

lengocgiang commented 5 years ago
export const Example = () => {
const [stackGrid, setStackGrid] = useState();

function handleUpdateLayout() {
    if (stackGrid) {
       stackGrid.updateLayout()
    }
}

return (
        <StackGrid
            gridRef={grid => setStackGrid(grid)}
            ....
)

Hope this help