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

On useView knobProps don't change if config change #85

Open
mauroreisvieira opened this issue May 30, 2022 · 0 comments
Open

On useView knobProps don't change if config change #85

mauroreisvieira opened this issue May 30, 2022 · 0 comments

Comments

@mauroreisvieira
Copy link

mauroreisvieira commented May 30, 2022

In my project, I'm using useView the problem is that the prop parameter is dynamic, initially, it's an empty object and only then it will be an object with all the props.

const [props, setProps] = React.useState({});


React.useEffect(() => {
    // eslint-disable-next-line unicorn/consistent-function-scoping
    const aux = require('./code/button/demos/exampleKnobs');
    setProps(aux.exampleKnobs.props);
}, []);

const { knobProps } = useView({ props });

from what I understand there is no useEffect that listens for config changes to reset knobsProps.

I try to add something like that to reset settings but keep new props (NOT previous object):

  useEffect(() => {
      dispatch({
          type: Action.Reset,
          payload: {
              code: initialCode,
              props: config.props,
              providerValue: provider.value,
          },
      });
  }, [config.props]);

Another option is to return the function to updateProps, which can receive an object or updateAll which can receive new configurations.

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

1 participant