react native中使用tailwind并配置自动补全

javascript 复制代码
import { View, Text } from 'react-native';
import tw from 'twrnc';

const MyComponent = () => (
  <View style={tw`p-4 android:pt-2 bg-white dark:bg-black`}>
    <Text style={tw`text-md text-black dark:text-white`}>Hello World</Text>
  </View>
);

当然也支持条件变量

javascript 复制代码
// pass multiple args
tw.style('text-sm', 'bg-blue-100', 'flex-row mb-2');
// falsy stuff is ignored, so you can do conditionals like this
tw.style(isOpen && 'bg-blue-100');

重要的来了!配置vscode的补全

参考自React Native - Tailwind CSS autocomplete in VSCode for twrnc package

补全插件还是用的Tailwind CSS IntelliSense,需要添加vscode的配置并手动新建两个空文件

在下图添加

新建一个空文件tailwind.config.js

然后就可以了

相关推荐
光影少年1 天前
原生DOM操作在React 中的注意事项
前端·javascript·react.js
YAwu112 天前
深入解析 React 炫彩鼠标跟随标题组件:从坐标定位到动画性能
前端·react.js
Ruihong2 天前
🎉 VuReact 1.9.0 发布,支持 Vue 3.4 defineModel 编译到 React
vue.js·react.js·面试
spmcor2 天前
React 架构师之路:Next.js 全栈革命(第八篇)
前端·react.js
假如让我当三天老蒯2 天前
React基础、进阶(学习用)
前端·react.js·面试
spmcor2 天前
为什么页面越用越卡?——React组件内存泄漏的排查与修复
react.js
jt君424263 天前
React Native JSI 深入剖析 — 第 7 部分中文技术整理:把 C++ 能力接到 iOS 和 Android
react native
天蓝色的鱼鱼3 天前
React Router v8 来了:react-router-dom 没了,老项目该怎么迁移?
前端·react.js
jt君424263 天前
React Native JSI 深入剖析 — 第 6 部分中文技术整理:跨 JS 与 C++ 两个世界的内存所有权
react native
无名氏同学3 天前
React 16-19 新特性
react.js