Ive been following the tutorial with no issues. On step 3 ill have to add the PublicUrlRegistrar tag.
Ill get this Error:
Error: This must be used within the ConnectProvider component.
22 | const useConnectDispatch = () => {
23 | const dispatch = useContext(ConnectDispatchContext);
24 | if (!dispatch) {
> 25 | throw new Error('This must be used within the ConnectProvider component.');
26 | }
27 | return dispatch;
28 | };
PublicUrlRegistrar.jsx Component
import React from "react";
import { Text } from "@blockstack/ui";
import { useConnect } from "@stacks/connect-react";
import { bufferCVFromString } from "@stacks/transactions";
import { CONTRACT_ADDRESS, CONTRACT_NAME } from "../assets/constants";
export const PublicUrlRegistrar = ({ userSession }) => {
const { doContractCall } = useConnect(); // <<<<<-------------------throwing error--------
const { username } = userSession.loadUserData();
const url = `${document.location.origin}/todos/${username}`;
const register = () => {
// do the contract call
doContractCall({
contractAddress: CONTRACT_ADDRESS,
contractName: CONTRACT_NAME,
functionName: "register",
functionArgs: [bufferCVFromString(username), bufferCVFromString(url)],
onFinish: (data) => {
console.log({ data });
},
});
};
return (
<>
<Text
color="blue"
cursor="pointer"
fontSize={1}
fontWeight="500"
onClick={() => {
// register the public URL
register();
}}
>
Register on-chain
</Text>
</>
);
};
It seems useConnect()
must be used in the ConnectProvider Component.
Even if I comment out the PublicUrlRegistrar.jsx functions and only leave line 8 ill get the same error.
Im trying to figure out how to use this library correctly
import { useConnect } from "@stacks/connect-react";
I've tried many things and been working on this for a while now with no way to progress. Any insights into this would be very helpful! Thank you!