-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract csrf token logic to custom hook
- Loading branch information
Kyle Zarazan
committed
Nov 20, 2024
1 parent
f4991ac
commit 25f3bbb
Showing
6 changed files
with
32 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/javascript/components/FoodsTable.tsx → app/javascript/components/foods/Index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/javascript/components/RecipeTable.tsx → app/javascript/components/recipes/Index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
const useCsrfToken = (): string => { | ||
const [csrfToken, setCsrfToken] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
const csrf_element = document.querySelector('meta[name="csrf-token"]') | ||
if (csrf_element) { | ||
setCsrfToken(csrf_element.getAttribute('content') || ""); | ||
} | ||
}, []); | ||
|
||
return csrfToken; | ||
}; | ||
|
||
export default useCsrfToken; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters