Skip to main content

Discovery Tech (1)

· One min read
  • React.useState(() => defaultValue)
  • Some open-source SaaS (Open source is not free)

React

  • useState(initialValue) can put callback for setting default value
const Modal = ({show, onHide, children, ...rest}) => {
const [config, setConfig] = useState({});

useEffect(() => {
const newConfig = buildConfig(rest);
setConfig(newConfig);
}, []);

return (
<Modal
show={show}
onHide={onHide}
{...config}>
{children}
</Modal>
);
}