You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Execute following command from the root folder to build the library. This creates a package in `dist/imagekitio-react.js` folder.
4
+
```sh
5
+
npm install # run for first time
6
+
npm run build
7
+
```
8
+
9
+
## Running test cases
10
+
11
+
The designated directory for tests is `/src/test` folder. All tests will be run against the assertion present in the `/src/test/__snapshot__` folder. To create this file you need to just run below command just once. Any update in the tests can be updated to by pressing `u` while the test environment is running.
12
+
13
+
Execute following command from the root folder to start testing.
14
+
```sh
15
+
npm run test
16
+
```
17
+
18
+
## Running sample frontend react app
19
+
20
+
Please refer to the sample app `Readme.md` for details.
21
+
22
+
## Running sample backend server
23
+
24
+
Please refer to the sample app `Readme.md` for details.
React SDK for [ImageKit.io](https://imagekit.io) which implements client-side upload and URL generation for use inside a react application.
8
+
React SDK for [ImageKit.io](https://imagekit.io), which implements client-side upload and URL generation for use inside a react application.
9
9
10
-
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
10
+
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
11
11
12
12
## Installation
13
13
@@ -22,63 +22,62 @@ Include the components in your code:
22
22
The library includes 3 Components:
23
23
*[IKContext](#IKContext)
24
24
25
-
*[IKImage](#IKImage)
25
+
*[IKImage - URL generation](#IKImage)
26
26
27
-
*[IKUpload](#file-upload)
27
+
*[IKUpload - File upload](#file-upload)
28
28
29
29
### IKContext
30
30
31
31
In order to use the SDK, you need to provide it with a few configuration parameters. The configuration parameters can be applied directly to the `IKImage` component or using an `IKContext` component. example:
`publicKey` and `urlEndpoint` are mandatory parameters for SDK initialization.
43
43
`authenticationEndpoint` is essential if you want to use the SDK for client-side uploads.
44
-
`transformationPosition` is optional. The default value for the parametere is `path`. Acceptable values are `path` & `query`
44
+
`transformationPosition` is optional. The default value for this parameter is `path`. Acceptable values are `path` & `query`
45
45
46
-
_Note: Do not include your Private Key in any clientside code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error_
46
+
_Note: Do not include your Private Key in any client-side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error_
47
47
48
-
### IKImage
48
+
### IKImage - URL generation
49
49
50
-
The IKImage component component defines a ImageKit Image tag. example usage:
50
+
The IKImage component component defines an ImageKit Image tag. example usage:
51
51
52
52
#### Using image path and image hostname or endpoint
`src` is the complete URL that is already mapped to ImageKit.
76
75
`path` is the location of the image in the ImageKit cloud. `urlEndpoint` + `path` makes the complete url.
77
76
`transformations` is optional. The transformations to be applied to a given image. It is declared in the form of an array of objects, where each object specifies the transformation you need. The values are mentioned below.
78
77
79
78
#### List of supported transformations
80
79
81
-
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/imagekit-docs/image-transformations). The SDK gives a name to each transformation parameter, making the code simpler and readable. If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using in the `url` function.
80
+
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations). The SDK gives a name to each transformation parameter, making the code simpler and readable. If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using in the `url` function.
82
81
83
82
| Supported Transformation Name | Translates to parameter |
The above image will apply transformation of width = 90 and height = 180 on the image. Since some transformatinos are destructive you might want to control the order in which the transforms are applied.
138
137
139
138
##### Chained Transforms
140
-
Chained transforms make it easy to specify the order the transform are applied. example:
139
+
Chained transforms make it easy to specify the order in which transformations are applied. example:
141
140
142
141
```js
143
142
consttransformations= [
@@ -150,7 +149,7 @@ const transformations = [
150
149
}
151
150
];
152
151
```
153
-
In the above case, rotation will be performed first and resizing according to width and aspect ratio will be performed afterwards.
152
+
In the above case, the rotation will be performed first, and resizing according to width and aspect ratio will be performed afterward.
154
153
155
154
#### Low Quality Image Placeholders (LQIP) for images
156
155
The SDK supports automatic support for LQIP for your images, if you set lqip to true in the image component. example:
@@ -162,30 +161,53 @@ The SDK supports automatic support for LQIP for your images, if you set lqip to
162
161
`quality` decided the quaility of placeholder image. It can be any numeric value, a low number means low quality, and high number means high quality.
163
162
164
163
##### How does the lqip work?
165
-
The component tries to keep the it simple, it loads a lower quality image using the quality parameter to load a lower quality image, which is then replaced with the actual quality image later.
164
+
The component tries to keep it simple. It loads a lower quality image using the quality parameter to load a lower quality image, which is then replaced with the actual quality image later.
166
165
167
-
####File Upload
166
+
###IKUpload - File Upload
168
167
The SDK provides a simple Component to upload files to the ImageKit Media Library. It accepts `fileName` parameter as a prop. The file parameter is provided as an input from the user.
169
168
170
-
Also make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`.
169
+
Also, make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`.
171
170
172
171
[Learn how to implement authenticationEndpoint](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#how-to-implement-authenticationendpoint-endpoint) on your server.
173
172
174
173
An example of this server is provided in the samples folder of the SDK.
`IKUpload` component accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#request-structure-multipart-form-data) as props e.g. `tags`, `useUniqueFileName`, `folder` etc.
187
186
188
-
#### Error Handling
187
+
You can use `onSuccess` and `onError` callbacks to handle success and failure, respectively. You can pass your custom functions to handle the response from API.
The fastest way to get started is by running the demo application. You can run the code locally. The source code is in samples/sample-app. For the instructions in [readme.md](https://github.com/imagekit-developer/imagekit-react/blob/test-case/samples/sample-app/README.md) file within [samples/sample-app](https://github.com/imagekit-developer/imagekit-react/tree/test-case/samples/sample-app) folder.
209
+
210
+
## Error Handling
189
211
We are using Error Boundaries to handle errors in the UI. `ErrorBoundary` is used to handle errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. example:
190
212
191
213
```js
@@ -196,3 +218,15 @@ We are using Error Boundaries to handle errors in the UI. `ErrorBoundary` is use
196
218
}]} />
197
219
</ErrorBoundary>
198
220
```
221
+
222
+
## Support
223
+
224
+
For any feedback or to report any issues or general implementation support please reach out to [[email protected]](mailto:[email protected])
0 commit comments