Hello,
I added a checkbox into my React app, basically it is privacy policy and need to be check from user.
As i understand, this can be done with Moralis objects but how can i save these data âfor each userâ in my Moralis database?
Thanks.
you can add a new column to user class where you can save it, or you can create a new table where you can save a pointer to a user and that value
import React from "react";
import { useMoralis } from "react-moralis";
function Checkbox() {
const { Moralis, user } = useMoralis();
const Policy = Moralis.Object.extend("Policy");
const policy = new Policy();
const policyHandler = () => {
policy.set(user, true);
policy.save();
};
return (
<div className="checkboxes">
<input type="checkbox" onChange={() => policyHandler()} />
<label>I agree to Privacy Policy.</label>
</div>
);
}
export default Checkbox;
Is this code alright?
this look like it only sets a field named user to true, but it doesnât connect it to a user
Ah okay, i almost figured it out.
I used setUserData function from useMoralis hook and then it worked but i guess boolean data type for privacy policy is not make sense.
Can you give an example about âpointerâ data type? I researched it but canât understand very well.
Thanks.
You donât have to do too much in your he case of pointer. When you save you save the user object for a column and for the other column the information that you want. It will be a little more complicated to get the data.
For the method that worked, what is the problem? You can create a column in user table of other type too if Boolean is not the right type for you.
Okay i figured it out but i have an another problem now
setUserData function just updates the old value, it is not âaddingâ on the old one.
I need historical data, how can i do this?
Thanks.
you could use a list maybe, or read current data and append to it