Skip to content

feature: set width dynamically #1

Description

@angelmtztrc

Hi,

I'm using this package on a little just-fun project, and I realised about one detail or problem.

I was building a layout, and one panel needs to have a dynamic width because it depends on the existence of another element (the values of the last are needed to calculate the final width of the panel).

For this, I'm using useState to store the initial and final result of the width, I also have a useEffect that sets the calculated data. In this example, I send the values (my state) to the <ResizePanel /> component via props, but the component does not take the state update and It does not trigger a rerender for that, so my new width is not set in the DOM but the contexts that are used inside of the package have the new values.

Ex.

const MyComponent = () => {
  const element = useRef(null)

  const [initialWidth, setInitialWidth] = useState(100)

  useEffect(() =. {
    if(element.current){
      // calculation...
      setInitialWidth(400)
    }
  }, [element])
  
  return (
    <ResizePanel
      // it would render 100 instead of 400
      initialWidth={initialWidth}    
    >
      {/* ... */}
    </ ResizePanel>
  )
}

Btw, would be amazing if support for computed values be added to the project :) (%, vw, rem, etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions