Skip to content

Instantly share code, notes, and snippets.

View BethanyDrake's full-sized avatar

Bethany BethanyDrake

  • Melbourne, Australia
View GitHub Profile
@BethanyDrake
BethanyDrake / UpdateProfileForm.jsx
Created October 30, 2025 20:31
server functions
'use client'
const UpdateProfileForm = () => {
const changeDisplayName = () => {
updateProfile({ displayName: 'My New Name'})
}
return (<button onClick={changeDisplayName}/>)
}
@BethanyDrake
BethanyDrake / page.jsx
Created October 30, 2025 20:06
Server Component
'use server'
const ExamplePage = async () => {
const initialData = await fetchData()
...
}
@BethanyDrake
BethanyDrake / ExamplePage.js
Last active October 30, 2025 20:24
whole separate bff
const UpdateProfileForm = () => {
const changeDisplayName = () => {
axios.post('/profile', {
displayName: 'My New Name',
})
}
return (<button onClick={changeDisplayName}/>)
}
export const ExamplePage = ({initialData}) => {
...
}
ExamplePage.getInitialProps = async () => {
return {
initialData: await fetchData()
}
}
export const ExampleComponent = () => {
const [isLoadinging, setIsLoading] = useState(true)
const [data, setData] = useState()
useEffect(() => {
fetchData().then((response) => {
setData(response)
setIsLoading(false)
})
}, [])
}
@BethanyDrake
BethanyDrake / ComponentC.jsx
Created January 17, 2024 11:05
Rewrite Enzyme test using RTL getByTestId
const ComponentC = () => {
return <ComponentA data-test-id="component-a" someProp="Goodbye?" />;
};
@BethanyDrake
BethanyDrake / ComponentB.jsx
Last active January 17, 2024 10:59
Rewriting Enzyme test with RTL getByText
const ComponentA = ({ someProp }) => {
return <div>{someProp}</div>;
};
export const ComponentB = () => {
return <ComponentA someProp="Hello!" />;
};