diff --git a/src/TapRating.tsx b/src/TapRating.tsx index ca010b7..be23a7b 100644 --- a/src/TapRating.tsx +++ b/src/TapRating.tsx @@ -109,18 +109,26 @@ export type TapRatingProps = { starStyle?: StyleProp; }; -const TapRating: React.FunctionComponent = (props) => { - const [position, setPosition] = useState(props.defaultRating); +const TapRating: React.FunctionComponent = + ({ + defaultRating = 3, + reviews = ["Terrible", "Bad", "Okay", "Good", "Great"], + count = 5, + showRating = true, + reviewColor = "rgba(230, 196, 46, 1)", + reviewSize = 25, + ...props + }) => { + const [position, setPosition] = useState(defaultRating); useEffect(() => { - const { defaultRating } = props; if (defaultRating === null || defaultRating === undefined) { setPosition(3); } else { setPosition(defaultRating); } - }, [props.defaultRating]); + }, [defaultRating]); const renderStars = (rating_array) => { return _.map(rating_array, (star) => { @@ -138,7 +146,6 @@ const TapRating: React.FunctionComponent = (props) => { setPosition(position); }; - const { count, reviews, showRating, reviewColor, reviewSize } = props; const rating_array = []; const starContainerStyle = [styles.starContainer]; @@ -183,15 +190,6 @@ const TapRating: React.FunctionComponent = (props) => { ); }; -TapRating.defaultProps = { - defaultRating: 3, - reviews: ["Terrible", "Bad", "Okay", "Good", "Great"], - count: 5, - showRating: true, - reviewColor: "rgba(230, 196, 46, 1)", - reviewSize: 25, -}; - const styles = StyleSheet.create({ ratingContainer: { backgroundColor: "transparent", diff --git a/src/components/Star.tsx b/src/components/Star.tsx index 2fe1a85..b269d43 100644 --- a/src/components/Star.tsx +++ b/src/components/Star.tsx @@ -23,7 +23,7 @@ export type StarProps = { starSelectedInPosition?: ( number ) => void; }; -const Star: React.FunctionComponent = props => { +const Star: React.FunctionComponent = ({starImage = STAR_IMAGE, selectedColor = "#f1c40f", unSelectedColor = "#BDC3C7", ...props}) => { const [selected, setSelected] = useState( false ); const springValue = new Animated.Value( 1 ); @@ -45,11 +45,8 @@ const Star: React.FunctionComponent = props => { }; const { - starImage, fill, size, - selectedColor, - unSelectedColor, isDisabled, starStyle } = props; @@ -76,12 +73,6 @@ const Star: React.FunctionComponent = props => { ); }; -Star.defaultProps = { - starImage: STAR_IMAGE, - selectedColor: "#f1c40f", - unSelectedColor: "#BDC3C7" -}; - export default Star; const styles = StyleSheet.create( {