diff --git a/src/Editmode.jsx b/src/Editmode.jsx index 3e211f0..1def872 100644 --- a/src/Editmode.jsx +++ b/src/Editmode.jsx @@ -2,12 +2,12 @@ import React from "react"; import { EditmodeContext } from "./EditmodeContext"; -export function Editmode({ children, projectId, defaultChunks }) { +export function Editmode({ children, projectId, defaultChunks, branchId }) { if (!projectId) { throw new Error(" is missing a valid projectId"); } - let branch; + let branch = branchId; return ( diff --git a/src/useChunk.js b/src/useChunk.js index 56197ff..c5f155f 100644 --- a/src/useChunk.js +++ b/src/useChunk.js @@ -6,7 +6,7 @@ import { api, computeContentKey } from './utilities' import { renderChunk, getCachedData, storeCache, sanitizeContent } from './utilities' export function useChunk(defaultContent = "", { identifier, type, contentKey, variables }) { - const { projectId, defaultChunks } = useContext(EditmodeContext); + const { projectId, defaultChunks, branch } = useContext(EditmodeContext); const [chunk, setChunk] = useState(undefined); if (!contentKey) { @@ -29,8 +29,6 @@ export function useChunk(defaultContent = "", { identifier, type, contentKey, va ); } - const url = `chunks/${identifier || contentKey}?project_id=${projectId}`; - useEffect(() => { // Render content (async () =>{ @@ -46,7 +44,8 @@ export function useChunk(defaultContent = "", { identifier, type, contentKey, va if (newChunk) setChunk(sanitizeContent(newChunk, variables, fallbackChunk)) // Fetch new data - let error; + const branchParams = branch ? `&branch_id=${branch}` : ""; + const url = `chunks/${identifier || contentKey}?project_id=${projectId}${branchParams}`; api .get(url) .then((res) => { @@ -56,13 +55,9 @@ export function useChunk(defaultContent = "", { identifier, type, contentKey, va setChunk(parsedChunk) } }) // Store chunk to localstorage - .catch((error) => console.log(error)); // Set error state - - if (error && identifier) { - console.warn( - `Something went wrong trying to retrieve chunk data: ${error}. Have you provided the correct Editmode identifier (${identifier}) as a prop to your Chunk component instance?` - ); - } + .catch((error) => { + console.warn(`Something went wrong trying to retrieve chunk data: ${error}. Have you provided the correct Editmode identifier (${identifier || contentKey}) as a prop to your Chunk component instance?`) + }); // Set error state })(); }, [cacheId]);