You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So this is my first react app. After much writing and refactoring, I have come to the conclusion as mentioned here.
I have little doubt with the current implementation, especially at point 1. Any help is appreciated.
In the FontIconPicker component, the props.value is passed from outside. Which is okay. But, depending on the fact that it has to be an array if props.isMulti is true, and a string or number if false, I think it is best if I create a derived state state.value within the component. With getDerivedStateFromProps it is kept in sync, while checking for validity.
Due to this nature, I am not explicitly calling this.setState. Rather I am relying on the parent to provide a handler function which would update its own state, which again would reflect on this.props.value for the FontIconPicker component. getDerivedStateFromProps would eventually set the correct state for FontIconPicker and this is what I am seeing in the dev tool too.
I need to persist the state of dropdown after close. This is why, I have necessary state variables isOpen, currentPage, currentCategory, currentSearch in the FontIconPicker. All of it gets passed through props to child components (if they need it). Whenever any child needs to change it, it fires a handler of the parent FontIconPicker which keeps things in sync. If a child's state depends on any of this, then the same is managed with getDerivedStateFromProps.
So this is my first react app. After much writing and refactoring, I have come to the conclusion as mentioned here.
I have little doubt with the current implementation, especially at point 1. Any help is appreciated.
In the
FontIconPicker
component, theprops.value
is passed from outside. Which is okay. But, depending on the fact that it has to be an array ifprops.isMulti
is true, and a string or number if false, I think it is best if I create a derived statestate.value
within the component. WithgetDerivedStateFromProps
it is kept in sync, while checking for validity.Due to this nature, I am not explicitly calling
this.setState
. Rather I am relying on the parent to provide a handler function which would update its own state, which again would reflect onthis.props.value
for theFontIconPicker
component.getDerivedStateFromProps
would eventually set the correct state forFontIconPicker
and this is what I am seeing in the dev tool too.I need to persist the state of dropdown after close. This is why, I have necessary state variables
isOpen, currentPage, currentCategory, currentSearch
in theFontIconPicker
. All of it gets passed throughprops
to child components (if they need it). Whenever any child needs to change it, it fires a handler of the parentFontIconPicker
which keeps things in sync. If a child's state depends on any of this, then the same is managed withgetDerivedStateFromProps
.I hope I am doing things right. At this stage, no styling or DOM positioning is handled, so it will look a bit weird. But the app is accessible from https://fonticonpicker.github.io/react-fonticonpicker/
The application I am building has a jQuery implementation here https://fonticonpicker.github.io/
Kindly see if any changes are required or if I am doing anything wrong.
/cc @micc83 @NiGhTTraX
The text was updated successfully, but these errors were encountered: