-
Build ErrorFailed to compile. Summaryhere is a link to a stackoverflow post i found.. it suggests that I have a syntax error, however being new to vercel, typescript, and react i'm unsure of how to implement this potential solution. this is the link to my file that is not working (I suspect all of my page.tsx have the same issue but this one simply comes up first in the build process) Extra credit: are there any other potential build issues forseen? Steps to ReproduceI attempt to build a deployment with the code found at https://github.com/reixyz22/Contact-Editor-Next/ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
const EditPage: React.FC<ContactPageProps> = ({ emailProp, editProp }) => {
const params = useParams();
const email = emailProp || decodeURIComponent(params.email as string);
const dispatch = useDispatch();
// State to manage the form inputs
const [newName, setNewName] = useState<string>('');
const [newEmail, setNewEmail] = useState<string>('');
const [newPhone, setNewPhone] = useState<string>('');
const handleSave = async () => {
let updateUrl = `/api/contacts/${email}/edit`; //edit contact API
if (email === "new"){ //add new contact API
updateUrl = `/api/contacts/add`;
}
const dataToSend = {
name: newName,
email: newEmail,
phone: newPhone,
};
const response = await fetch(updateUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(dataToSend),
});
if (response.ok) {
const updatedContactData: Contact = await response.json();
console.log('Contact updated successfully');
dispatch(toggleHide(email)); //hide the edit interface
} else {
const errorData = await response.json();
console.error('Failed to update contact:', errorData.error);
}
if (email === "new" && response.ok){ //fix the display, so we can show your newly added contact right away
dispatch(clearEmail("new"));
dispatch(setEmail(newEmail));
}
};
if (!editProp) return <div/>; // Return nothing if edit mode is off
return (
<div>
<h1 style={{color: 'darkred'}}>{email}</h1>
<input
type="text"
value={newName}
onChange={(e) => setNewName(e.target.value)}
placeholder="Enter new name"
style={{display: 'block', margin: '10px 0'}}
/>
<input
type="email"
value={newEmail}
onChange={(e) => setNewEmail(e.target.value)}
placeholder="Enter new email"
style={{display: 'block', margin: '10px 0'}}
/>
<input
type="text"
value={newPhone}
onChange={(e) => setNewPhone(e.target.value)}
placeholder="Enter new phone"
style={{display: 'block', margin: '10px 0'}}
/>
<button onClick={handleSave}>💾 Save</button>
<button onClick={() => dispatch(toggleHide(email))}>🔙 Back</button>
</div>
);
};
export default EditPage; You are trying to pass in props that won't work your default export can only take in interface RouteProps {
params: {
email: string;
};
} Also would recommend using export default function NamePage({
params,
}: RouteProps): JSX.Element {
return(
// ....
);
} |
Beta Was this translation helpful? Give feedback.
-
This discussion was automatically locked because the community moved to a new site. Please join us at vercel.community |
Beta Was this translation helpful? Give feedback.
@reixyz22