Checkbox true/false data save to database in React

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?

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);;

  return (
    <div className="checkboxes">
      <input type="checkbox" onChange={() => policyHandler()} />
      <label>I agree to Privacy Policy.</label>

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

1 Like

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.

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 :slight_smile:
setUserData function just updates the old value, it is not “adding” on the old one.
I need historical data, how can i do this?

you could use a list maybe, or read current data and append to it