Jun 22, 2020 10:27 AM
The Custom Blocks contest deadline is approaching! Do you have questions about releasing or debugging your block? We’re hosting our third live Ask Me Anything (AMA) session in this thread on Wednesday (6/24) at 11am PT.
Billy Littlefield and Tim Deng from our platform engineering team will be ready to answer any development questions you have.
We’ll be picking 3 questions at random to win a $40 Amazon gift card. Any solutions offered by the community will be included in the draw as well. You can even start posting your questions now, and we’ll be answering questions live from 11am - 11:30am PT on Wednesday. See you there!
Jun 24, 2020 12:01 PM
Adding your .block
folder to your git ignore will prevent it from syncing to your git remote, but it’ll still be on your local computer. If you’re the only one working on the custom block and you only use one computer, this isn’t an issue (otherwise, everyone else collaborating on your block will need the same app and base IDs). If you’re concerned about other users, ignoring your .block
folder should be fine! They can choose “Remix from GitHub” when creating a custom block, and it will automatically create a .block
folder for them.
Jun 24, 2020 12:11 PM
Ah, interesting use case. With the useRecordActionData
hook, the data always will be the latest press, so you wouldn’t register a separate click. I think you can register a callback directly, though, using registerRecordActionDataCallback which should execute the registered callback on every push (even if its the same button).
I wonder if there’s value in providing a timestamp or ID in the action payload to distinguish between these clicks using the hook.
EDIT: Another solution here would be to use a usePrevious
hook, e.g.
function usePrevious(value) {
const ref = React.useRef();
React.useEffect(() => {
ref.current = value;
});
return ref.current;
}
This way, you can compare the value returned by useRecordActionData()
for subsequent presses. Even if the same record is clicked, the object returned by useRecordActionData
on a subsequent button press will be a new object compared to the value cached by usePrevious
.
function MyComponent() {
const buttonData = useRecordActionData();
const lastButtonData = usePrevious(buttonData);
useEffect(() => {
if (buttonData !== lastButtonData && buttonData) {
// perform logic for button press
}
}, [buttonData, lastButtonData])
// ... rest of component ...
}
Jun 24, 2020 12:16 PM
I think that’s the most logical way – barebones example:
function MyComponent() {
const [isLoading, setIsLoading] = useState(false);
function fetchTheThing() {
setIsLoading(true);
fetch('example.com').then(response => {
// do stuff with response
setIsLoading(false);
})
}
return (
<Box>
{isLoading ? (
<Loader />
) : (
<RestOfApp />
)}
</Box>
)
}
Jun 24, 2020 12:27 PM
Correct, currently only creators can create, release, and install blocks in a given base. It’s not currently possible to install a custom block without creator permissions. If the developer/creator is removed from the base, the block will remain. Releasing, publishing, and sharing blocks is something we’re thinking about for the future in order to reduce friction for both the developer and consumers.
Jun 24, 2020 12:42 PM
And that’s a wrap! If you have any further questions, you can always find us in the custom blocks beta forum. The winners for this week are @Yuriy_Klyuch, @kuovonne, and @Kirill_Madorin!
With the contest deadline fast approaching (July 6th), we’ll be hosting our last AMA in the custom blocks contest series next week with a twist! Instead of AMA, we’ve got a fun “AYA” format planned. The post will be up EoD Friday and will be open until 6pm PT on Thursday, July 1. We’ll be giving out Amazon gift cards to three of the most insightful posts. Stay tuned!
Jun 24, 2020 12:42 PM
Exciting to see your block in action! I’ll have to refrain from providing feedback now, assuming this is an entrant in the current blocks contest. Happy to answer your questions, though!
RecordQueryResultOpts
, but if you create a view in the main product that performs this filtering, you can select records from just that view.