Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
Creating react app with acl, getting casl react t.on error

I'm just getting started with casl and it seems like I must be missing something. I created a file called can.js and it is exactly like the example in the docs:

import { createContext } from 'react';
import { createContextualCan } from '@casl/react';

export const AbilityContext = createContext();
export const Can = createContextualCan(AbilityContext.Consumer);

in my App.tsx I am using

let caslAbilities = new Ability(abilitiesJson); // from an API call returning json formatted abilities as described in docs
<AbilityContext.Provider value={caslAbilities}> 
   <Main />
</AbilityContext.Provider> 

Then inside Main.ts I define some routes like this:

import {Can} from "../Auth/can"; // the file defined above
<Can I={"read"} a={"Post"}> // this should always be false with my test abilities json
    <Route path="/reporting">
        <ReportingHome />
    </Route>
</Can>

When you click the restricted route the app throws an error:

Uncaught TypeError: t.on is not a function

Am I missing something obvious?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda