Skip to main content

useAddReview

The useAddReview hook is used to add review and rating for a product.

ParamsDescription
setNamesetState for name
setEmailsetState for email
setRatingsetState for rating
setTitlesetState for title
setBodysetState for body
userCurrent user data
onSubmitReviewasync Function, call on review submission
isLoadingboolean value to show loading on submitting review
namename of the reviewer
emailemail of the reviewer
ratingrating given by the reviewer
titletitle of the review
bodybody of the review
note

State are handled inside hook, call setState on input value change directly.

Usage


const AddReview = (props) => {
const {
onSubmitReview,
isLoading,
setName,
setRating,
setEmail,
setBody,
setTitle,
name,
email,
rating,
body,
title,
user,
} = useAddReview(props);

return (
<View>
<Input
label="Name"
placeholder="Enter your name (public)"
onChangeText={setName}
value={name}
style={[styles.input, styles.inputHeight]}
/>
<Input
label="Email"
placeholder="Enter your email (private)"
onChangeText={setEmail}
value={email}
editable={user?.email ? false : true}
style={[styles.input, styles.inputHeight]}
/>
<AddStarRating
label={`Rating (${rating})`}
rating={rating}
setRating={setRating}
/>
<Input
label="Review Title"
placeholder="Give your review a title"
onChangeText={setTitle}
value={title}
style={[styles.input, styles.inputHeight]}
/>
<Input
label="Review"
placeholder="Write your review here"
onChangeText={setBody}
value={body}
multiline
numberOfLines={4}
style={[styles.input, styles.textAreaHeight]}
/>
<Button onPress={onSubmitReview} loading={isLoading} status="dark">
Submit Review
</Button>
</View>
);
};