Skip to content

Commit

Permalink
Merge pull request #577 from commercelayer/fix/remove-axios
Browse files Browse the repository at this point in the history
Remove `axios` dependency
  • Loading branch information
acasazza committed Aug 27, 2024
2 parents bb1f384 + 467410c commit a7c1bb3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"overrides": {
"postcss@<8.4.31": ">=8.4.31",
"graphql@>=16.3.0 <16.8.1": ">=16.8.1",
"axios@>=0.8.1 <1.6.0": ">=1.6.0",
"vite@>=4.4.0 <4.4.12": ">=4.4.12",
"@babel/traverse@<7.23.2": ">=7.23.2",
"vite@>=4.0.0 <=4.5.1": ">=4.5.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
"@stripe/stripe-js": "^4.3.0",
"@tanstack/react-table": "^8.17.3",
"@types/iframe-resizer": "^3.5.13",
"axios": "^1.7.3",
"braintree-web": "^3.106.0",
"frames-react": "^1.1.2",
"iframe-resizer": "^4.4.5",
Expand Down Expand Up @@ -225,4 +224,4 @@
"peerDependencies": {
"react": ">=18.0.0"
}
}
}
17 changes: 15 additions & 2 deletions packages/react-components/src/context/ExternalFunctionContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createContext } from 'react'
import axios from 'axios'

interface Context {
url: string | null
Expand All @@ -14,7 +13,21 @@ type CallExternalFunction = (params: {
export const callExternalFunction: CallExternalFunction = async ({
url,
data
}) => await axios.post(url, data)
}) => {
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})

if (!response.ok) {
throw new Error('Failed to call external function')
}

return await response.json()
}

const ExternalFunctionContext = createContext<Context>({
url: null,
Expand Down
10 changes: 3 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7c1bb3

Please sign in to comment.