useAddReview
The useAddReview
hook is used to add review and rating for a product.
Params | Description |
---|---|
setName | setState for name |
setEmail | setState for email |
setRating | setState for rating |
setTitle | setState for title |
setBody | setState for body |
user | Current user data |
onSubmitReview | async Function, call on review submission |
isLoading | boolean value to show loading on submitting review |
name | name of the reviewer |
email of the reviewer | |
rating | rating given by the reviewer |
title | title of the review |
body | body 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>
);
};