Skip to content

Commit 49cb361

Browse files
committed
Custom hooks are functions that use other hooks
1 parent c73fbfd commit 49cb361

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

hackathon/spacecraft/src/components/StarshipCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { Image } from "~/components/Image";
88

99
import type { StarshipProps } from "../../api/types";
1010

11-
import { useImage } from "../hooks/useImage";
1211
import { Routes } from "../navigation/Routes";
12+
import { getImageSource } from "../utils/getImageSource";
1313
import { withAnimated } from "../utils/withAnimated";
1414

1515
const AnimatedCard = withAnimated(Card);
@@ -27,7 +27,7 @@ interface StarshipDetailsScreenParams {
2727
export const StarshipCard = ({ index, ship }: StarshipCardProps) => {
2828
const { cost_in_credits: price, manufacturer, name: title } = ship;
2929

30-
const source = useImage(title);
30+
const source = getImageSource(title);
3131

3232
const handleBuy = () => {
3333
Alert.alert("Give me the money!");

hackathon/spacecraft/src/hooks/useImage.ts renamed to hackathon/spacecraft/src/utils/getImageSource.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
2-
* A custom hook that returns the image source for a given starship title.
2+
* Returns the image source for a given starship title.
33
*
44
* @param {string} title - The title of the starship.
5-
* @returns {any} The image source corresponding to the starship title.
65
*
76
* @example
8-
* const imageSource = useImage("Millennium Falcon");
9-
* // imageSource will be the path to the Millennium Falcon image.
7+
* ```
8+
* const imageSource = getImageSource("Millennium Falcon");
9+
* ```
10+
* imageSource will be the path to the Millennium Falcon image.
1011
*/
11-
export const useImage = (title: string) => {
12+
export const getImageSource = (title: string) => {
1213
const imageName = `${title.toLowerCase().replace(" ", "")}`;
1314

1415
let source;

0 commit comments

Comments
 (0)