Skip to content

Commit

Permalink
feat(react/color-style): apply default props
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Sep 15, 2024
1 parent d72be6c commit f42945e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/react/src/color-style/ColorStyleProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ensurePlainObject } from 'ensure-type';
import memoize from 'micro-memoize';
import React, { useCallback, useEffect, useState } from 'react';
import { useDefaultProps } from '../default-props';
import defaultColorStyle from './color-style';
import { ColorStyleContext } from './context';

Expand All @@ -10,12 +11,13 @@ const ensureColorStyle = (colorStyle) => {

const getMemoizedState = memoize(state => ({ ...state }));

const ColorStyleProvider = ({
children,
defaultValue: defaultValueProp,
value: valueProp,
onChange: onChangeProp,
}) => {
const ColorStyleProvider = (inProps) => {
const {
children,
defaultValue: defaultValueProp,
value: valueProp,
onChange: onChangeProp,
} = useDefaultProps({ props: inProps, name: 'ColorStyleProvider' });
const [colorStyle, setColorStyle] = useState(ensureColorStyle(valueProp ?? (defaultValueProp ?? defaultColorStyle)));

useEffect(() => {
Expand Down

0 comments on commit f42945e

Please sign in to comment.